#! /usr/bin/python2
# coding=utf-8
import os
import threading
import urllib2
from Tkinter
import *
#from multiprocessing import Process
from multiprocessing
import Process
, Value
, Array
val_price =
20
val_percent =
5 /
100
def 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()
#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 change_percent
, price_current
def p_stock(flg_price
, arr_price
, flg_percent
, arr_percent):
"""
A doubling function that can be used by a process
"""
code_list = [
'sz300127', 'sz000639', 'sh600718', 'sh600452', 'sh600489']
i =
0
for code
in code_list:
percent
, price = get_price(code)
#print code, price
name = code +
" " + percent +
" " + price
#print flg_price[i], flg_percent[i], arr_price[i], float(price),arr_percent[i],float(percent)
if (((
float(price) > arr_price[i]
and 0 != arr_price[i]) )
and (
1 == flg_price[i])):
timer = threading.Timer(
5, func)
timer.start()
flg_price[i] =
0
#print flg_price[i]
creatfram(name)
elif (((
float(percent) > arr_percent[i]
and 0 != arr_percent[i]))
and (
1 == flg_percent[i])):
timer = threading.Timer(
5, func)
timer.start()
flg_percent[i] =
0
#print flg_percent[i]
creatfram(name)
#else:
#print "idle",flg_price[i], flg_percent[i]
i +=
1
#print "i", i
if __name__ ==
'__main__':
num =
10
arr_flg_price = Array(
'i', range(num))
arr_flg_percent = Array(
'i', range(num))
arr_price = Array(
'd', range(num))
arr_percent = Array(
'd', range(num))
for i
in range(
len(arr_flg_price)):
arr_flg_price[i] =
1
arr_flg_percent[i] =
1
arr_price[i] =
0.0
arr_percent[i] =
0.0
arr_price[
0] =
22
arr_percent[
0] =
5.21
arr_price[
1] =
20
arr_percent[
1] =
5.21
while True:
proc = Process(
target=p_stock
, args=(arr_flg_price
, arr_price
, arr_flg_percent
, arr_percent))
proc.start()
proc.join()
转载请注明原文地址: https://ju.6miu.com/read-700423.html