import json
import requests
from pyecharts.charts import Map,Geo
from pyecharts import options as opt
from pyecharts.globals import GeoType,RenderType
url = "https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5"
resp = requests.get(url = url).json()
data = json.loads(resp["data"])
china_Info = data["chinaTotal"]
china_children_Info = data["areaTree"][0]["children"]
china_data = []
result = ""
DeathMax = 0
for i in range(len(china_children_Info)):
name = china_children_Info[i]["name"]
confirm = china_children_Info[i]["total"]["confirm"]
'''
#各省份死亡人数
if (china_children_Info[i]["total"]["dead"] > DeathMax):
DeathMax = china_children_Info[i]["total"]["dead"]
result = china_children_Info[i]["name"]
'''
china_data.append([name,confirm])
china_total = "确诊%s\t疑似%s\t死亡%s\t治愈%s\t更新时间%s"%(
china_Info["confirm"],china_Info["suspect"],
china_Info["dead"],china_Info["heal"],
data["lastUpdateTime"])
print(china_total)
geo = (
Geo(init_opts=opt.InitOpts(
width="1200px",
height="600px",
bg_color="#404a59",
page_title="全国疫情实时报告",
renderer=RenderType.SVG,
theme="white"
))
.add_schema(
maptype="china",
itemstyle_opts=opt.ItemStyleOpts(
color="rgb(49,60,72)",
border_color="rgb(0,0,0)"
)
)
.add(
series_name="Geo",
data_pair=china_data,
type_=GeoType.EFFECT_SCATTER
)
.set_series_opts(
label_opts=opt.LabelOpts(is_show=False),
effect_opts=opt.EffectOpts(scale=6)
)
.set_global_opts(
visualmap_opts=opt.VisualMapOpts(
min_=0,
max_=china_data[0][1]
),
title_opts=opt.TitleOpts(
title="全国疫情地图",
subtitle=china_total,
pos_left="center",
pos_top="20px",
title_textstyle_opts=opt.TextStyleOpts(color="#fff")
),
legend_opts=opt.LegendOpts(is_show=False)
)
)
geo.render("./中国疫情地图.html")
geo.render_notebook()