SoFunction
Updated on 2024-11-20

Complete code for Python3 to monitor the outbreak

The specific code is shown below:

import requests
import json
from  import Map, Geo
from pyecharts import options as opts
from  import GeoType, RenderType
url = '/g2/getOnsInfo?name=disease_h5'
datas = ((url=url).json()['data'])
china = datas['areaTree'][0]['children']
data = []
for i in range(len(china)):
([china[i]['name'], china[i]['total']['confirm']])
confirm = datas['chinaTotal']['confirm']
suspect = datas['chinaTotal']['suspect']
dead = datas['chinaTotal']['dead']
heal = datas['chinaTotal']['heal']
lastUpdateTime = datas['lastUpdateTime']
print(confirm, suspect, dead, lastUpdateTime)
china_total = "Confirmed:" + str(confirm) + " Suspicious:" + str(suspect) + " Death:" + str(dead) + " Healing:" + str(
heal) + " Update:" + lastUpdateTime
geo = (
Geo(init_opts=(width="1200px", height="600px", bg_color="#404a59", page_title="National Outbreak Real-Time Report".
renderer=, theme="white")) # Set drawing size, background color, page title, drawing type
.add_schema(maptype="china", itemstyle_opts=(color="rgb(49,60,72)",
border_color="rgb(0,0,0)")) # China map, map area colors, area border colors
.add(series_name="geo", data_pair=data, type_=GeoType.EFFECT_SCATTER) # Set the map data, animated as ripple effect scatter
.set_series_opts( # Setup series configuration
label_opts=(is_show=False), # Do not show Label
effect_opts=(scale=6)) # Setting the ripple effect zoom ratio
.set_global_opts( # Setting the global series configuration
# visualmap_opts=(min_=0, max_=sum / len(datas)), # set the visual map configuration, with the maximum value being the average value
title_opts=(title="National Epidemic Map.", subtitle=china_total, pos_left="center", pos_top="10px",
title_textstyle_opts=(color="#fff")),
# Set title, subtitle, title position, text color
legend_opts=(is_show=False), # No legend displayed
)
)
(path="./")

Running effect diagram

summarize

The above is the complete code for Python3 to monitor the epidemic, I hope it will help you, and thank you very much for your support of my website!