How to use python to refresh fund valuation in real time
This article mainly shows you "how to use python real-time refresh fund valuation", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "how to use python real-time refresh fund valuation" this article.
Upper source code
Import requestsimport jsonimport osfrom prettytable import PrettyTableimport timefundlist = ['163817017'. '003860'] def GetFundJsonInfo (fundcode): url = "http://fundgz.1234567.com.cn/js/"+fundcode+".js" response = requests.get (url) fundDataInfo = response.text.split (' ({') [1] fundDataInfo ='{'+ fundDataInfo.split ('})') [0] +'} 'fundDataInfo = json.loads (fundDataInfo) return fundDataInfo os.system (" cls ") while True: table = PrettyTable ([" name "," yesterday's net worth " "Real time valuation", "growth rate") for fund in fundlist: myfund = GetFundJsonInfo (fund) table.add_row ([myfund ['name'], myfund [' dwjz'], myfund ['gsz'], myfund [' gszzl']]) print (table) time.sleep (5) os.system ("cls")
Description
Prettytable prints fund data through table formatting to facilitate browsing of data.
Os.system ("cls") is used for screen cleaning and refreshing.
Original response content
Jsonpgz ({"fundcode": "163817", "name": "Bank of China Convertible Bond Enhancement B", "jzrq": "2021-09-10", "dwjz": "3.1120", "gsz": "3.1127", "gszzl": "0.02", "gztime": "2021-09-13 14:54"}); these are all the contents of the article "how to use python to refresh fund valuation in real time". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!