股票监控报警系统

 
  
# 股票监控报警系统-for Tencent
# 可设置股票池监控多支股票,可根据涨幅范围自动报警

import requests
from bs4 import BeautifulSoup
import win32api,win32con
import re
import time

class stock:
    def stock(self,id):
        # 无限循环监控,直到警报拉起
        while True:
            message = []
            time_list= []
            # 时间
            now_time = time.strftime('[%Y-%m-%d %H:%M:%S]', time.localtime(time.time()))
            message.append(now_time[1:-2])
            time_list.append(now_time[1:-2])

            for i in range(len(id)):
                stock_id1 = id[i]
                url = 'http://gu.qq.com/' + stock_id1 + '/gp'
                soup=self.request(url)

                # 股票名称
                stock_name=soup.find('h1', class_='col-1-1').get_text()

                print('------------------------\n', now_time[1:-2])
                print('股票:',stock_name)
                # 股票代码
                stock_id = soup.find('h1', class_='col-1-2').get_text()
                print('股票代码:', stock_id)
                # print('----------------')

                # 实时价格
                realtime_price = soup.find('span',class_='data').get_text()
                zhangdie=soup.find('div',class_='item-2').find_all('span')
                # 涨跌价格
                zhangdie_price=zhangdie[0].get_text()
                # 涨跌%
                zhangdie_percent=zhangdie[1].get_text()
                print('当前价:',realtime_price)
                print('涨跌价:',zhangdie_price)
                print('涨跌幅:',zhangdie_percent)


                # 所有信息(昨收,今开,,,振幅)
                all=soup.find('div',class_='col-2 fr').find_all('li')
                for a in range(12):
                    a=all[a].get_text()
                    print(a)

                # 根据涨跌百分比执行消息框
                zhangdie_percent_re = ''.join(re.findall('(.*?)%', zhangdie_percent))

                if float(zhangdie_percent_re)>zhangdie_percent_range[0] :
                    message.append('\n%s:\n最新价:%s  涨跌额:%s  涨跌幅:%s  %s  %s  %s  %s  %s  %s\n' % (stock_name,realtime_price, zhangdie_price,zhangdie_percent,all[0].get_text(),all[1].get_text(),all[2].get_text(),all[3].get_text(),all[8].get_text(),all[9].get_text()))
                elif float(zhangdie_percent_re)<=zhangdie_percent_range[1]:
                    message.append('\n%s:\n最新价:%s  涨跌额:%s  涨跌幅:%s  %s  %s  %s  %s  %s  %s\n' % (stock_name,realtime_price, zhangdie_price,zhangdie_percent,all[0].get_text(),all[1].get_text(),all[2].get_text(),all[3].get_text(),all[8].get_text(),all[9].get_text()))

            if message !=time_list:
                print('*******************************')
                message=''.join(message)
                win32api.MessageBox(0,message,'股价警报系统-按涨跌幅范围 '+str(zhangdie_percent_range[1])+'%'+'


你可能感兴趣的:(没事写着玩)