程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python for cities epidemic data

編輯:Python
Hello everyone, I want to get the epidemic data of each city, how to change this cycle,Learning python for the first time
import requests

import json

New dictionary to store data

res_list = {}
req = requests.get('https://api.inews.qq.com/newsqa/v1/query/inner/publish/modules/list?modules=diseaseh5Shelf%27)
req_data = json.loads(req.text).get('data')
req_data = req_data.get('diseaseh5Shelf')
print('The second interface json verification passed')

Get relevant data as needed

lastupdatetime = req_data['lastUpdateTime']
chinatotal = req_data['chinaTotal']
chinaadd = req_data['chinaAdd']
areaTree = req_data['areaTree'][0]
res_list['lastUpdateTime'] = lastupdatetime
res_list['chinaTotal'] = chinatotal
res_list['chinaAdd'] = chinaadd
res_list['citydata'] = []

loop to obtain the data of each region

#for i_areaTree in areaTree['children']:

i_areaTree = i_areaTree

prov_name = i_areaTree['name']

for i_areaTree_end in i_areaTree['children']:
city_name = i_areaTree_end['name']
if city_name in ['North Sea']:
print(city_name)
#if prov_name in['Beihai']:

for i_areaTree_end in i_areaTree['children']:
i_city_data = {}
i_city_data['prov_name'] = prov_name
i_city_data['city_name'] = i_areaTree_end['name']
i_city_data['local_confirm_add'] = i_areaTree_end['today']['local_confirm_add']#Add local
i_city_data['wzz_add'] = i_areaTree_end['today']['wzz_add']#Add asymptomatic
i_city_data['mediumRiskAreaNum'] = i_areaTree_end['total']['mediumRiskAreaNum']#Number of medium risk areas
i_city_data['highRiskAreaNum'] = i_areaTree_end['total']['highRiskAreaNum']#Number of middle risk areas
i_city_data['suspect'] = 0
i_city_data['dead'] = i_areaTree_end['total']['dead']
i_city_data['heal'] = i_areaTree_end['total']['heal']
i_city_data['grade'] = '' if (i_areaTree_end['total'].get('grade') is None) else
i_areaTree_end['total']['grade']
res_list['citydata'].append(i_city_data)

print(res_list)

![img](

I https://imgmid class="md.csdnimg.cn/release/static/image/mid/ask/173648956856143.png "#left")

Solution ideas and tried methods


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved