python 涨跌价格幅度 大盘凑合
来源:互联网 发布:网络大电影没办法发行 编辑:程序博客网 时间:2024/04/30 05:17
#! /usr/bin/python2# coding=utf-8import osimport threadingimport urllib2import timefrom Tkinter import *#from multiprocessing import Processfrom multiprocessing import Process, Value, Array, Managerdef func(): os._exit(0)def creatfram(name): root = Tk() w = Label(root, text=name) w.pack() root.geometry('150x20+0+0') root.resizable(width=False, height=False) root.mainloop()def get_price(code): url = 'http://hq.sinajs.cn/?list=%s' % code #print url req = urllib2.Request(url) #print req # 如果不需要设置代理,下面的set_proxy就不用调用了。由于公司网络要代理才能连接外网,所以这里有set_proxy… # req.set_proxy('proxy.XXX.com:911', 'http') content = urllib2.urlopen(req).read() str = content.decode('gbk', 'ignore') data = str.split('"')[1].split(',') #print data name = "%-6s" % data[0] price_current = "%-6s" % float(data[3]) change_percent = (float(data[3]) - float(data[2])) * 100 / float(data[2]) change_percent = "%-6s" % round(change_percent, 2) #print("股票名称:{0} 涨跌幅:{1} 最新价:{2}".format(name, change_percent, price_current)) return change_percent, price_current, namedef p_stock(code_list): """ A doubling function that can be used by a process """ for code in code_list: var_code = code['code'] price_high = code['price_high'] flg_price_high = code['flg_price_high'] percent_high = code['percent_high'] flg_percent_high = code['flg_percent_high'] price_low = code['price_low'] flg_price_low = code['flg_price_low'] percent_low = code['percent_low'] flg_percent_low = code['flg_percent_low'] percent, price, name = get_price(var_code) #print code, price info = var_code + " " + percent + " " + price flg_show = 0 #print code['code'], float(price), float(percent), " alarm ",code['price_high'], code['percent_high'] if (((float(price) > price_high and 0 != price_high) ) and (1 == flg_price_high)): flg_show = 1 code['flg_price_high'] = 0 if (((float(percent) > percent_high and 0 != percent_high)) and (1 == flg_percent_high)): flg_show = 1 code['flg_percent_high'] = 0 if (((float(price) < price_low and 0 != price_low) ) and (1 == flg_price_low)): flg_show = 1 code['flg_price_low'] = 0 if (((float(percent) < percent_low and 0 != percent_low)) and (1 == flg_percent_low)): flg_show = 1 code['flg_percent_low'] = 0 if 1 == flg_show: print var_code, name, float(price), float(percent), "alarm high", price_high, percent_high, " alarm low", price_low, percent_low timer = threading.Timer(5, func) timer.start() creatfram(info)def stock_header(str): t1 = ('60', '900') t2 = ('000', '002', '300', '200') t3 = ('399001','399006') if str.startswith(t1): str2 = 'sh' + str elif str.startswith('000001'): str2 = 's_sh' + str elif str.startswith(t3): str2 = 's_sz' + str elif str.startswith(t2): str2 = 'sz' + str else: str2 = str print str return str2def file_read(A, mgr): file = open("date.txt",'rU') text = file.read() lines = text.split('\n') for line in lines: # print line # 将每一行分隔开,提取姓名和联系方式 i =0 l = ['600127', '0', '0', '0', '0'] for cell in line.split(','): if not cell: break l[i] = cell i += 1 str = l[0] str2 = stock_header(str) #print i, "----------", str2, "----------", l[1], "----------", l[2] A.append(mgr.dict(code=str2, price_high=float(l[1]), percent_high=float(l[2]), price_low=float(l[3]), percent_low=float(l[4]), flg_price_high=1, flg_percent_high=1, flg_price_low=1, flg_percent_low=1)) file.close()if __name__ == '__main__': # print sys.getdefaultencoding() reload(sys) sys.setdefaultencoding('utf-8') # print sys.getdefaultencoding() mgr = Manager() A = Manager().list() file_read(A, mgr) #for s in A: # print s time_interval = 60 * 10 flg_time = 0 old = 0 while True: localtime = time.localtime(time.time()) if 9 >= localtime.tm_hour or 15 <= localtime.tm_hour : print localtime.tm_hour break proc = Process(target=p_stock, args=(A, )) proc.start() proc.join() if 0 == flg_time: for code in A: if (0 == code['flg_price_high'] or 0 == code['flg_percent_high'] or 0 == code['flg_price_low'] or 0 == code['flg_percent_low']): flg_time = 1 old = time.time() print "---------------- ------------", old if ((1 == flg_time) and ((time.time() - old) > (time_interval))) : flg_time = 0 print "++++++++++++++++++++++", time.time() for code in A: code['flg_price_high'] = 1 code['flg_percent_high'] = 1 #print A[0]['flg_price_high'], A[0]['flg_percent_high']'''date.txt 格式 普通股票 上涨到,涨幅,下跌到,跌幅大盘 涨幅,0,跌幅,0000001,1,0,-0.2,0399001,1,0,-1,0399006,1,0,-1,0300127,24,5,18,-1000639,25,5,15,-5600718'''
0 0
- python 涨跌价格幅度 大盘凑合
- 证券的交易价格相对于上一个交易日收盘价格的涨跌幅度不得超过10%
- 使用AdaBoost预测预测大盘涨跌
- 大盘未来三个月的涨跌走势:3000点归来
- 使用SVM预测大盘涨跌的简单策略
- 空调补贴下降七成 价格涨跌趋势不明
- python读取大盘指数
- 浦发银行的短期价格及大盘趋势
- 大盘跳水,下跌5个点后回到7.78的价格
- Python 过滤次新股、停牌、涨跌停
- Python 畅销价格 python画图
- 一切凑合
- java调用python脚本文件大盘点
- 涨跌停板
- 涨跌幅
- 误差幅度
- python大盘点:全局变量、局部变量、类变量、实例变量
- python大盘点:全局变量、局部变量、类变量、实例变量
- Connection: keep-alive
- JsonUtils
- 第八周项目2-建立链串的算法库
- linus 一生只为寻欢笑
- ios developer tiny share-20161013
- python 涨跌价格幅度 大盘凑合
- MyEclipse2015+Tomcat+MAVEN+SVN项目环境搭建
- Linux基本常用命令
- 第八周项目5—— 计数的模式匹配
- Oracle PL/SQL编程 存储过程和函数
- 第八周项目3 公共字符
- 二分查找
- 字符集和字符编码(编码系列-1)
- Xutils的bitmapUtils的缓存理解