#! /usr/bin/python2 # coding=utf-8 import os import threading import urllib2 from Tkinter import * from multiprocessing import Process def func(): os._exit(0) def creatfram(name): root = Tk() w = Label(root, text=name) w.pack() root.geometry('100x20+0+0') root.resizable(width=False, height=False) root.mainloop() print sys.getdefaultencoding() reload(sys) sys.setdefaultencoding('utf-8') print sys.getdefaultencoding() 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(',') 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 name, price_current def p_stock(): """ A doubling function that can be used by a process """ code_list = ['sz300036', 'sz000977', 'sh600718', 'sh600452', 'sh600489'] for code in code_list: name, price = get_price(code) print name, price name = name + price if float(price) > 5: timer = threading.Timer(5, func) timer.start() creatfram(name) if __name__ == '__main__': while True: proc = Process(target=p_stock, args=()) proc.start() proc.join()
Python 股票数据 弹窗自动关闭
最新推荐文章于 2024-01-25 16:42:56 发布