Chinaunix首页 | 论坛 | 博客
  • 博客访问: 666573
  • 博文数量: 36
  • 博客积分: 8068
  • 博客等级: 中将
  • 技术积分: 1377
  • 用 户 组: 普通用户
  • 注册时间: 2005-04-11 22:36
文章存档

2011年(2)

2010年(1)

2009年(20)

2008年(13)

我的朋友

分类: Python/Ruby

2010-08-26 12:06:28


     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) |
给主人留下些什么吧!~~

chinaunix网友2010-08-29 08:31:30

Download More than 1000 free IT eBooks: http://free-ebooks.appspot.com