<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      python實例31[My Stock Info]

       

      本程序使用python3.1實現的一個運行于Windows的控制臺小程序,用來顯示你所關心的股票的實時價格。

      1)每隔一分鐘跟新一次,當然你可以改為更短的時間間隔;

      2)控制臺彩色顯示的python模塊為WConio,需要單獨下載:http://newcenturycomputers.net/projects/wconio.html

      3)webservice來源于sina,感謝sina,例如http://hq.sinajs.cn/list=sh600547, 返回的結果如下:

      var hq_str_sh600547="山東黃金,51.02,51.00,52.71,52.86,50.68,52.70,52.72,16389139
      ,850524809,3000,52.70,52500,52.69,100,52.67,28849,52.66,7400,52.65,1200,52.72,43
      77,52.75,11200,52.76,20000,52.77,4000,52.78,2010-12-31,15:02:06";

       

       

      4) 也可以使用其他的股票web service (http://www.webxml.com.cn/WebServices/ChinaStockWebService.asmx/getStockInfoByCode?theStockCode=sh600547),返回的結果如下:

      <?xml version="1.0" encoding="utf-8" ?> 
      <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://WebXml.com.cn/">
        
      <string>sh600547</string> 
        
      <string>山東黃金</string> 
        
      <string>2011-01-04 14:46:20</string> 
        
      <string>53.15</string> 
        
      <string>52.71</string> 
        
      <string>53.18</string> 
        
      <string>0.44</string> 
        
      <string>52.77</string> 
        
      <string>53.79</string> 
        
      <string>0.83%</string> 
        
      <string>138375.48</string> 
        
      <string>73669.8408</string> 
        
      <string>53.15</string> 
        
      <string>53.16</string> 
        
      <string>-48.30%</string> 
        
      <string>53.15 / 94.00</string> 
        
      <string>53.13 / 11.00</string> 
        
      <string>53.12 / 11.00</string> 
        
      <string>53.11 / 6.00</string> 
        
      <string>53.10 / 304.00</string> 
        
      <string>53.16 / 30.70</string> 
        
      <string>53.17 / 265.65</string> 
        
      <string>53.18 / 481.99</string> 
        
      <string>53.19 / 194.00</string> 
        
      <string>53.20 / 249.50</string> 
        
      </ArrayOfString>

       

       

      程序:(Mystockinfo.py) 

      import urllib.request

      class Utility:
          
      def ToGB(str):
              
      return str.decode('gb2312')
          
          
      def ReadStocksToArray(file):
              file 
      = open(file, 'r')
              stocks 
      = []
              
      if file:
                  
      for line in file:
                      stocks.append(line.rstrip(
      "\n"))
                  file.close()
              
      else:
                  
      print ("Error Opening File.")
              
      return stocks
              
      class ColorConsole:
          
      def PrintStockInfoTitle():
              
      import datetime
              
      print(datetime.datetime.now())    
              
      print("Name".ljust(10+ "ID".ljust(10+ "CurrentPrice".ljust(20+ "Percent".ljust(10))  
              
      print('*****************************************************')
          
      def PrintStockInfoTitleWithColor():
              
      import WConio
              WConio.settitle(
      "My Stock Info")
              WConio.clrscr()
              ColorConsole.PrintStockInfoTitle()
              
          
      def PrintStockInfoItem(stockitem):
              
      print(stockitem[0].ljust(10+ str(stockitem[1]).ljust(10+  str(stockitem[2]).ljust(20+ str(stockitem[3]).ljust(10))

          
      def PrintStockInfoItemWithColor(stockitem):
              
      import WConio
              WConio.textcolor(WConio.WHITE)
              
      if(stockitem[3]> 0.0):
                  WConio.textcolor(WConio.RED)
                  ColorConsole.PrintStockInfoItem(stockitem)
              
      else:
                  WConio.textcolor(WConio.GREEN)
                  ColorConsole.PrintStockInfoItem(stockitem)
              WConio.textcolor(WConio.WHITE)
                  
      class StockInfo:        
          
      def GetStockStrByNum(num):
              f 
      = urllib.request.urlopen('http://hq.sinajs.cn/list='+ str(num))
              stockstr 
      = ""
              
      if f:
                  stockstr 
      = f.readline()
                  f.close() 
              
      return  stockstr  
                      
          
      def ParseStockStr(stockstr):
              stockitem 
      = []
              id 
      = stockstr[13:19]
              slist
      =stockstr.split(',')
              name
      =slist[0][-4:]
              yesterdayendprice
      =slist[2]
              nowprice
      =slist[3]
              upgraderate
      =(float(nowprice)-float(yesterdayendprice))/float(yesterdayendprice)
              upgraderate
      = upgraderate * 100
              stockitem.append(name)
              stockitem.append(id)
              stockitem.append(nowprice)
              stockitem.append(upgraderate)
              
      return stockitem
                    
          
      def GetStockInfo(num):
              str
      =StockInfo.GetStockStrByNum(num)
              strGB
      =Utility.ToGB(str)
              
      return StockInfo.ParseStockStr(strGB)       

      def RunWithOutColor():     
          stocks 
      = Utility.ReadStocksToArray('Stocks.txt')
          ColorConsole.PrintStockInfoTitle()
          
      for stock in stocks:
              s 
      = StockInfo.GetStockInfo(stock)
              ColorConsole.PrintStockInfoItem(s)
              
      def RunWithColor():
          stocks 
      = Utility.ReadStocksToArray('Stocks.txt')
          ColorConsole.PrintStockInfoTitleWithColor()
          
      for stock in stocks:
              s 
      = StockInfo.GetStockInfo(stock)
              ColorConsole.PrintStockInfoItemWithColor(s)

      def Main():
          
      while(1):
              
      #RunWithOutColor()
              RunWithColor()
              
      import time
              time.sleep(
      60)

      Main()

        

      數據輸入: (stocks.txt 此文件需要跟Mystockinfo.py在統一目錄下,你可以自由的增加自己關注的股票代碼)

      sh601601
      sh600547
      sz300027
      sh600196
      sz002299
      sh601766

        

      運行結果:

       

      運行: (MyStockInfo.bat 雙擊此文件即可運行了,或者還可以對此文件創建桌面快捷方式,再桌面上直接運行)

      c:\python31\python.exe mystock.py

        

      如果希望在python2.6下運行,則需要

      1)在所有的類的靜態函數前加上   @staticmethod  ;

      2) 修改urllib.request為urllib2;

       

      希望大家能夠繼續改進和共享!

       

      完!

      posted @ 2010-12-15 20:04  iTech  閱讀(2961)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 蜜臀av午夜精品福利| 国产中文字幕精品免费| 久热久精久品这里在线观看| 一区二区三区精品偷拍| 91久久性奴调教国产免费| 深夜释放自己在线观看| 欧美性猛交xxxx乱大交极品| 影音先锋女人AA鲁色资源| 亚洲人成小说网站色在线| 欧美日韩一线| 又大又长粗又爽又黄少妇毛片| 大荔县| 内射无套内射国产精品视频| 亚洲国产精品日韩在线| 夜夜爽妓女8888888视频| 男女无遮挡激情视频| 免费无码成人AV片在线| 少妇人妻偷人精品免费视频| 图片区小说区av区| 国产av国片精品一区二区| 久久久久久久无码高潮| 噜噜综合亚洲av中文无码| 福利一区二区视频在线| 亚洲欧美日韩一区在线观看| 日韩卡一卡2卡3卡4卡| 国产精品午夜福利合集| 成人性生交大片免费看r链接| 亚洲老女人区一区二视频| 国产中文三级全黄| 白河县| 午夜一区二区三区视频| 中文字幕乱码一区二区免费| 沁源县| 国产成人精品18| 黑人欧美一级在线视频| 亚洲第一香蕉视频啪啪爽| 一本久道久久综合中文字幕| 亚洲欧洲∨国产一区二区三区 | 中文字幕亚洲一区二区三区| 99亚洲男女激情在线观看| 国产精品污一区二区三区|