摸鱼小工具_利用python实时刷新基金估值 效果预览

上源码

import requests
import json
import os
from prettytable import prettytable
import time

fundlist = ['163817','161017','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(["名称","昨日净值","实时估值","增长率"])
    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")

说明

  • prettytable 通过表格格式化打印基金数据便于浏览数据
  • os.system(“cls”) 用于清屏刷新
  • 原始的响应内容
jsonpgz({"fundcode":"163817","name":"中银转债增强债券b","jzrq":"2021-09-10","dwjz":"3.1120","gsz":"3.1127","gszzl":"0.02","gztime":"2021-09-13 14:54"});

到此这篇关于利用python实时刷新基金估值(摸鱼小工具)的文章就介绍到这了,更多相关python基金估值内容请搜索www.887551.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持www.887551.com!