Python command line view stock Basic market data

Source: Internet
Author: User

Write a python version of the gadget that can be used at work to brush your attention to the stock information. The Python version is 3.4.1, with the following code:

#!/usr/bin/env python#-*-coding:utf-8-*-import urllib.request#debug=truedebug=falseclass utility:def ToGB (str): if (Debug): Print (str) return Str.decode (' gb2312 ') class Stockinfo: "" "0: Unknown 1: Name 2: Code 3: When Previous price 4: Ups and downs 5:6%: Volume (Lot) 7: Turnover (million) 8:9: Total Market Value "" "Def Getstockstrbynum (num): f= URLLIB.R        Equest.urlopen (' Http://qt.gtimg.cn/q=s_ ' + str (num)) if (Debug): Print (F.geturl ()) if (Debug): Print (F.info ())        #return like:v_s_sz000858= "51~ wuliangye ~000858~18.10~0.01~0.06~94583~17065~~687.07"; Return F.readline () f.close () def parseresultstr (RESULTSTR): if (Debug): Print (RESULTSTR) slist=res ULTSTR[14:-3] if (Debug): Print (slist) slist=slist.split (' ~ ') if (Debug): Print (slist) #print (' Print (' Stock name: ', slist[1]) print (' Stock code: ', Slist[2]) print (' Current price : ', slist[3]) print (' Ups and downs: ', slist[4])       Print (' Up%: ' slist[5], '% ') print (' Volume (Lot): ', slist[6]) print (' Turnover (million): ', slist[7]) #print ( ' Date and time is: ', dateandtime) print (' ******************************* ') def getstockinfo (num): str=st Ockinfo.getstockstrbynum (num) strgb=utility.togb (str) STOCKINFO.PARSERESULTSTR (STRGB) if __name__ = = ' __main_  _ ': Stocks = [' sh600888 ', ' sz300104 ', ' sz300027 ', ' sz000919 '] for the stock in Stocks:StockInfo.GetStockInfo (stock)


Python command line view stock Basic market data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.