Python 腾讯接口之全球/全国疫情数据获取

# 全国数据

import json
import requests
import pandas as pd

url_name = 'https://api.inews.qq.com/newsqa/v1/query/inner/publish/modules/list?modules=chinaDayList,chinaDayAddList,nowConfirmStatis,provinceCompare'
html_name = requests.get(url_name)
data_name=json.loads(html_name.text)['data']['provinceCompare']
city = [k for k,v in data_name.items()]
writer = pd.ExcelWriter('全国疫情历史数据.xlsx')
for j in city:   
    data1=[]
    url='https://api.inews.qq.com/newsqa/v1/query/pubished/daily/list?province='+ j
    html = requests.get(url)
    html.text
    data=json.loads(html.text)['data']
    for i in data:
        data2={}
        data2['日期']=str(i['year'])+'年'+i['date'][0:2]+'月'+i['date'][3:5]+'日'
        data2['省份']=i['province']
        data2['确诊']=i['confirm']
        data2['死亡']=i['dead']
        data2['治愈']=i['heal']
        data2['现有']=data2['确诊'] - data2['治愈'] - data2['死亡']
        data2['新增确诊']=i['newConfirm']
        data2['新增治愈']=i['newHeal']
        data2['新增死亡']=i['newDead']
        data1.append(data2)
    df=pd.DataFrame(data1)
    df.to_excel(writer, sheet_name=j,index=0)
writer.save()


# 全球数据

import json
import requests
import pandas as pd

url_name = 'https://api.inews.qq.com/newsqa/v1/automation/modules/list?modules=FAutoGlobalStatis,FAutoGlobalDailyList,FAutoCountryConfirmAdd'
html_name = requests.get(url_name)
data_name=json.loads(html_name.text)['data']['FAutoCountryConfirmAdd']
FAutoCountry = [k for k,v in data_name.items()]
writer = pd.ExcelWriter('全球疫情历史数据.xlsx')
for j in FAutoCountry:   
    data1=[]
    url='https://api.inews.qq.com/newsqa/v1/automation/foreign/daily/list?country='+ j
    html = requests.get(url)
    html.text
    data=json.loads(html.text)['data']
    for i in data:
        data2={}
        data2['日期']=str(i['y'])+'年'+i['date'][0:2]+'月'+i['date'][3:5]+'日'
        data2['确诊']=i['confirm']
        data2['死亡']=i['dead']
        data2['治愈']=i['heal']
        data2['现有']=data2['确诊'] - data2['治愈'] - data2['死亡']
        data2['新增确诊']=i['confirm_add']
        data1.append(data2)
    df=pd.DataFrame(data1)
    df.to_excel(writer, sheet_name=j,index=0)
writer.save()
上一篇:C# winform点击生成二维码


下一篇:“21天好习惯”第一期-5