1 #!/usr/bin/python
2 # kf701, 2010-08-26
3
4 import urllib
5 import string
6
7 mystock = [
8 ['000963',500,23.854],
9 ['002001',300,34.581],
10 ['002003',500,23.694],
11 ['002204',500,21.953],
12 ]
13
14 url = "\
15 s_sh000001,\
16 s_sz399001,\
17 s_sz002003,\
18 s_sz002001,\
19 s_sz000963,\
20 s_sz002204,\
21 s_sz000839,\
22 s_sz002194,\
23 s_sh600893,\
24 s_sh600839,\
25 s_sh600418,\
26 s_sh600104"
27
28 def name_in_mystock (name):
29 i = 0
30 for s in mystock:
31 i = i + 1
32 if name.find (s[0]) is not -1:
33 return i
34 return 0
35
36
37 data = urllib.urlopen(url).read()
38
39 line = data.split('\n')
40 for vv in line:
41 aa = vv.split(',');
42 if aa[0] :
43 name = aa[0].split('_')[3].replace('"','').replace('=',' ')
44 cur = string.atof(aa[1])
45 wave = string.atof(aa[2])
46 per = string.atof(aa[3])
47 money = string.atof(aa[5].replace('";',''))
48
49 index = name_in_mystock (name)
50 if index :
51 mypri = mystock[index-1][2]
52 mypro = (cur - mypri) * mystock[index-1][1];
53 print '%s %10.2f %10.2f %10.2f %12d w %10.3f %10.2f' %(name, cur, wave, per, money, mypri, mypro)
54 else:
55 print '%s %10.2f %10.2f %10.2f %12d w' %(name, cur, wave, per, money)
56
阅读(6657) | 评论(1) | 转发(0) |