-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcorona_virus_BI_chinese.py
668 lines (593 loc) · 33.3 KB
/
corona_virus_BI_chinese.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
import json
import requests
import pandas as pd
from pyecharts.charts import *
from pyecharts import options as opts
from pyecharts.commons.utils import JsCode
from pyecharts.globals import ThemeType, ChartType
from bs4 import BeautifulSoup
from pyecharts.render import make_snapshot
from snapshot_selenium import snapshot
from retrying import retry
import random
from pyecharts.datasets.coordinates import get_coordinate, search_coordinates_by_keyword
# 抓取数据(2020年2月24日更新:腾讯网页有变化,新增一个网页存放新增数据)
url = 'https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5&callback='
URL = 'https://view.inews.qq.com/g2/getOnsInfo?name=disease_other&callback='
user_agents = ['Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20130406 Firefox/23.0', \
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0', \
'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533+ \
(KHTML, like Gecko) Element Browser 5.0', \
'IBM WebExplorer /v0.94', 'Galaxy/1.0 [en] (Mac OS X 10.5.6; U; en)', \
'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)', \
'Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14', \
'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) \
Version/6.0 Mobile/10A5355d Safari/8536.25', \
'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) \
Chrome/28.0.1468.0 Safari/537.36', \
'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0; TheWorld)'\
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36']
headers= {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.8",
"Cache-Control": "max-age=0",
"Connection": "keep-alive",
"Upgrade-Insecure-Requests": "1",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"User-Agent": random.choice(user_agents)}
try:
response = requests.get(url, proxies={'http': 'http://127.0.0.1:1080','https': 'https://127.0.0.1:1080'},\
headers = headers , timeout = 30)
response2 = requests.get(URL, proxies={'http': 'http://127.0.0.1:1080','https': 'https://127.0.0.1:1080'},\
headers = headers , timeout = 30)
res = response.json()
res2 = response2.json()
response_test = requests.get('http://httpbin.org/get', proxies={'http': 'http://127.0.0.1:1080','https': 'https://127.0.0.1:1080'},\
headers=headers, timeout=30)
print('ip test:',response_test.text)
print(url)
print(URL)
response.raise_for_status()
response2.raise_for_status()
response.encoding = response.apparent_encoding
response2.encoding = response2.apparent_encoding
#print(response.text)
except requests.exceptions.RequestException as e:
print('*'*50,str(e))
print(time.strftime('%Y-%m-%d %H:%M:%S'))
time.sleep(random.random()*3)
soup = BeautifulSoup(response.text, "lxml")
soup2 = BeautifulSoup(response2.text, "lxml")
#soup.prettify()
#soup2.prettify()
# print(soup.prettify())
# print("pretty print done!!!!!!!!!!!!!!!!")
# print('\n')
# print(soup2.prettify())
# print("pretty2 print done!!!!!!!!!!!!!!!!")
# print('\n')
#response = requests.get('https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5&callback=').json()
data = json.loads(res['data'])
data2 = json.loads(res2['data'])
#print('data:#######################',data)
# print('\n')
# print('data2:#######################',data2)
# print('\n')
#'chinaTotal': {'confirm': 78959, 'heal': 36157, 'dead': 2791, 'nowConfirm': 40011, 'suspect': 2308, 'nowSevere': 7952}, 'chinaAdd': {'confirm': 329, 'heal': 3626, 'dead': 44, 'nowConfirm': -3341, 'suspect': -50, 'nowSevere': -394}, 'isShowAdd': True, 'showAddSwitch': {'all': True, 'confirm': True, 'suspect': True, 'dead': True, 'heal': True, 'nowConfirm': True, 'nowSevere': True}, 'areaTree': [{'name': '中国', 'today': {'confirm': 329, 'isUpdated': True}, 'total': {'confirm': 78959, 'suspect': 2308, 'dead': 2791, 'deadRate': '3.53', 'showRate': False, 'heal': 36157, 'healRate': '45.79', 'showHeal': True}, 'children': [{'name': '湖北', 'today': {'confirm': 318, 'confirmCuts': 0, 'isUpdated': True}, 'total': {'confirm': 65914, 'suspect': 0, 'dead': 2682, 'deadRate': '4.07', 'showRate': False, 'heal': 26403, 'healRate': '40.06', 'showHeal': True}, 'children': [{'name': '武汉', 'today': {'confirm': 313, 'confirmCuts': 0, 'isUpdated': True}, 'total': {'confirm': 48137, 'suspect': 0, 'dead': 2132, 'deadRate': '4.43', 'showRate': False, 'heal': 15826, 'healRate': '32.88', 'showHeal': True}},
# 国内
lastUpdateTime = data['lastUpdateTime']
chinaTotal = data['chinaTotal']
chinaTotal['累计确诊'] = chinaTotal['confirm']
chinaTotal['累计死亡'] = chinaTotal['dead']
chinaTotal['累计治愈'] = chinaTotal['heal']
chinaTotal['现有疑似'] = chinaTotal['suspect']
chinaTotal['现有确诊'] = chinaTotal['nowConfirm']
chinaTotal['现有重症'] = chinaTotal['nowSevere']
del chinaTotal['confirm']
del chinaTotal['dead']
del chinaTotal['heal']
del chinaTotal['suspect']
del chinaTotal['nowConfirm']
del chinaTotal['nowSevere']
sum = chinaTotal['累计确诊'] + chinaTotal['现有疑似']
chinaAdd = data['chinaAdd']
chinaAdd['新增累计确诊'] = chinaAdd['confirm']
chinaAdd['新增累计死亡'] = chinaAdd['dead']
chinaAdd['新增累计治愈'] = chinaAdd['heal']
chinaAdd['新增现有疑似'] = chinaAdd['suspect']
chinaAdd['新增现有确诊'] = chinaAdd['nowConfirm']
chinaAdd['新增现有重症'] = chinaAdd['nowSevere']
del chinaAdd['confirm']
del chinaAdd['dead']
del chinaAdd['heal']
del chinaAdd['suspect']
del chinaAdd['nowConfirm']
del chinaAdd['nowSevere']
areaTree = data['areaTree']
china_data = areaTree[0]['children'] #province block
china_list = []
for x in range(len(china_data)):
province = china_data[x]['name'] #province name
province_list = china_data[x]['children'] #city blocks under a province
for y in range(len(province_list)): #loop city lists under a province
city = province_list[y]['name'] #city names
total = province_list[y]['total'] #累计数据 under 'total' block it's a list of statistics: confirm/suspect/dead/heal
today = province_list[y]['today'] #新增数据 for a city: today's info (confirm under 'today' block means no. confirmed for that city)
china_dict = {'province': province, 'city': city, 'total': total, 'today': today}
china_list.append(china_dict)
foreign_data = data2['foreignList']
country_List = []
for y in range(len(foreign_data)):
country_List.append(foreign_data[y]['name'])
# for z in country_list:
# \"confirmAdd\":851,\"confirmAddCut\":0,\"confirm\":5186,\"suspect\":0,\"dead\":31,\"heal\":31,
print('country list:{}'.format(country_List))
# 定义数据处理函数
#累计确诊
def confirm(x):
confirm = eval(str(x))['confirm']
return confirm
#累计死亡
def dead(x):
dead = eval(str(x))['dead']
return dead
#累计治愈
def heal(x):
heal = eval(str(x))['heal']
return heal
# 现有疑似
def suspect(x):
suspect = eval(str(x))['suspect']
return suspect
# 现有确诊
def nowConfirm(x):
nowConfirm = eval(str(x))['nowConfirm']
return nowConfirm
# 现有重症
def nowSevere(x):
nowSevere = eval(str(x))['nowSevere']
return nowSevere
# 现有疑似
def deadRate(x):
deadRate = eval(str(x))['deadRate']
return deadRate
# 现有疑似
def healRate(x):
healRate = eval(str(x))['healRate']
return healRate
china_data = pd.DataFrame(china_list)
#print('china_data:##########')
#print(china_data.head())
# 函数映射
#累计确诊/死亡/治愈
china_data['confirm'] = china_data['total'].map(confirm)
china_data['dead'] = china_data['total'].map(dead)
china_data['heal'] = china_data['total'].map(heal)
#现有疑似/确诊/重症/
china_data['suspect'] = china_data['total'].map(suspect)
# china_data['nowConfirm'] = china_data['total'].map(nowConfirm)
# china_data['nowSevere'] = china_data['total'].map(nowSevere)
#新增累计确诊/死亡/治愈
china_data['addconfirm'] = china_data['today'].map(confirm)
# china_data['adddead'] = china_data['today'].map(dead)
# china_data['addheal'] = china_data['today'].map(heal)
#新增现有疑似/确诊/重症
# china_data['addsuspect'] = china_data['today'].map(suspect)
# china_data['addnowConfirm'] = china_data['today'].map(addnowConfirm)
# china_data['addnowSevere'] = china_data['today'].map(addnowSevere)
china_data['deadRate'] = china_data['total'].map(deadRate)
china_data['healRate'] = china_data['total'].map(healRate)
china_data = china_data[
["province", "city", "confirm", "suspect", "dead", "heal", "addconfirm"]] #info N/A today: "addsuspect", "adddead", "addheal"
#china_data.head()
#Global数据处理
foreignList = pd.DataFrame(data2['foreignList'])
print('foreignList: {}'.format(foreignList))
foreign_data = list(zip(foreignList['name'], foreignList['confirm']))
print('foreign_data: {}'.format(foreign_data))
global_data = pd.DataFrame(data2['foreignList'])
# global_data['confirm'] = global_data['name'].map(confirm)
# global_data['suspect'] = global_data['name'].map(suspect)
# global_data['dead'] = global_data['name'].map(dead)
# global_data['heal'] = global_data['name'].map(heal)
# global_data['deadRate'] = global_data['total'].map(deadRate)
# global_data['healRate'] = global_data['total'].map(healRate)
# global_data['addconfirm'] = global_data['name'].map(confirmAdd)
#print(type(global_data))
#print("global data before merge:######################", global_data)
print('\n')
global_data = pd.DataFrame(foreign_data, columns=['name','confirm'])
#global_data.reindex(global_data['name'])
#print(global_data)
tmp_jp = global_data.loc[4,'confirm'] + global_data.loc[3,'confirm']
print("日本本土+钻石号邮轮:-----------",tmp_jp)
#加一行‘日本’
global_data.loc[len(global_data)+1] = ('日本',tmp_jp)
global_data.loc[len(global_data)+2] = ('中国', chinaTotal['累计确诊'])
world_name = pd.read_excel("国家中英文对照Echarts_clean_name.xlsx")
#print("df_global_data2merge: ########## ", global_data)
#print(world_name)
global_data = pd.merge(global_data, world_name, left_on="name", right_on="中文", how="inner")
print("global data after merge:######################", global_data)
# global_data = global_data[
# ["name", "英文", "confirm", "suspect", "dead", "heal", "addconfirm"]] # info N/A today: "addsuspect", "adddead", "addheal"]]
# global_data.head()
# 日数据处理
chinaDayList = pd.DataFrame(data2['chinaDayList'])
chinaDayList = chinaDayList[['confirm', 'suspect', 'dead','heal','nowConfirm', 'nowSevere', 'deadRate', 'healRate','date']] #deadRate是网页隐藏元素!
#chinaDayList.head()
# 日新增数据处理
chinaDayAddList = pd.DataFrame(data2['chinaDayAddList'])
chinaDayAddList = chinaDayAddList[[ 'confirm', 'suspect', 'dead', 'heal', 'deadRate', 'healRate','date']]
#chinaDayAddList.head()
# 数据可视化
#print("chinaTotal.values:")
#print(chinaTotal.values())
chinaTotal_p1 = [chinaTotal['累计确诊'], chinaTotal['累计死亡'], chinaTotal['累计治愈']]
chinaTotal_p2 = [chinaTotal['现有疑似'], chinaTotal['现有确诊'], chinaTotal['现有重症']]
# 饼图
total_pie = (
Pie(init_opts=opts.InitOpts(theme=ThemeType.LIGHT, width='500px', height='350px', bg_color="transparent"))
.add("", [list(z) for z in zip(['累计确诊 ', '累计死亡 ', '累计治愈 '], chinaTotal_p1)],
center=["48%", "60%"], radius=[80, 95], )
.add("", [list(z) for z in zip(['现有疑似 ', '现有确诊 ', '现有重症 '], chinaTotal_p2)],
center=["48%", "60%"], radius=[50, 65], )
.add("", [list(z) for z in zip(chinaAdd.keys(), chinaAdd.values())], center=["48%", "60%"], radius=[0, 35])
.set_global_opts(title_opts=opts.TitleOpts(title="全国总量", pos_bottom=0,
title_textstyle_opts=opts.TextStyleOpts(color="#00FFFF")),
legend_opts=opts.LegendOpts(textstyle_opts=opts.TextStyleOpts(color="#FFFFFF")))
.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}:{c}")))
#print("global_data:################ ",global_data)
print('\n')
# 全球疫情地图
world_map = (
Map(init_opts=opts.InitOpts(theme=ThemeType.WESTEROS))
.add("", [list(z) for z in zip(list(global_data["英文"]), list(global_data["confirm"]))], "world",
is_map_symbol_show=False)
.set_series_opts(label_opts=opts.LabelOpts(is_show=False),
toolbox_opts=opts.ToolboxOpts(orient='vertical', pos_right="10%"))
.set_global_opts(visualmap_opts=opts.VisualMapOpts(is_piecewise=True, background_color="transparent",
textstyle_opts=opts.TextStyleOpts(color="#F5FFFA"),
pieces=[
{"min": 101, "label": '>100', "color": "#893448"},
{"min": 10, "max": 100, "label": '10-100',
"color": "#fb8146"},
{"min": 1, "max": 9, "label": '1-9',
"color": "#fff2d1"},
])))
# 中国疫情地图绘制
# 数据处理
#省份汇总数据也可以直接读取
area_data = china_data.groupby("province")["confirm"].sum().reset_index()
area_data.columns = ["province", "confirm"]
area_map = (
Map(init_opts=opts.InitOpts(theme=ThemeType.WESTEROS))
.add("", [list(z) for z in zip(list(area_data["province"]), list(area_data["confirm"]))], "china",
is_map_symbol_show=False, label_opts=opts.LabelOpts(color="#fff"),
tooltip_opts=opts.TooltipOpts(is_show=True), zoom=1.2, center=[105, 30])
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(title_opts=opts.TitleOpts(title="中国疫情分布图", pos_top='5%',
title_textstyle_opts=opts.TextStyleOpts(color="#FF0000")),
visualmap_opts=opts.VisualMapOpts(is_piecewise=True, pos_right=0, pos_bottom=0,
textstyle_opts=opts.TextStyleOpts(color="#F5FFFA"),
pieces=[
{"min": 1001, "label": '>1000', "color": "#893448"},
{"min": 500, "max": 1000, "label": '500-1000',
"color": "#ff585e"},
{"min": 101, "max": 499, "label": '101-499',
"color": "#fb8146"},
{"min": 10, "max": 100, "label": '10-100',
"color": "#ffb248"},
{"min": 0, "max": 9, "label": '0-9',
"color": "#fff2d1"}])))
city_data = china_data.groupby('city')['confirm'].sum().reset_index()
city_data.columns = ["city", "confirm"]
def is_city(item):
'''
判断一个城市能否在Geo地图上被找到
:param item: 城市名
:return: T/F
'''
lists_1 = []
lists_1.append(item)
lists_2 = [10]
geo = Geo()
geo.add_schema(maptype="china")
try:
geo.add("确诊城市", [list(z) for z in zip(lists_1, lists_2)])
return True
except TypeError as e:
return False
city_index = []
i = 0
for item in city_data['city']:
if is_city(item) == False:
city_index.append(i)
i += 1
print("未通过geos函数的城市:$$$$$$$$$$$$$$$$$$", city_data['city'][city_index])
# 设置匹配阈值
#COORDINATES.cutoff = 0.7
#print(search_coordinates_by_keyword(city_area_list[10][:2]))
##############清除不存在的地点,否则Geo会报错###############
# 城市坐标处理,清洗数据需要注意模糊查询
for x in city_index:
del (city_data['city'][x])
del (city_data['confirm'][x])
#严重确诊城市:
city_index_ = []
i = 0
for item in city_data['confirm']:
if item > 500:
city_index_.append(i)
i += 1
serious_city = [] # 严重城市
serious_submit = [] # 严重人数
for y in city_index_:
serious_city.append(list(city_data['city'])[y])
serious_submit.append(list(city_data['confirm'])[y])
#一般确诊城市:
city_index__ = []
i = 0
for item in city_data['confirm']:
if item < 1001:
city_index__.append(i)
i += 1
cfm_city = [] # 一般确诊城市
cfm_submit = [] # 一般确诊人数
for z in city_index__:
cfm_city.append(list(city_data['city'])[z])
cfm_submit.append(list(city_data['confirm'])[z])
list_1 = ["拉萨"]
list_2 = [1]
print('\n')
print("print serious city############:")
#print(serious_city,serious_submit)
print([list(z) for z in zip(list(serious_city), list(serious_submit))])
print('\n')
print("一般确诊城市:########")
print([list(z) for z in zip(cfm_city, cfm_submit)])
print('###########################\n')
area_heat_geo = (
Geo(init_opts=opts.InitOpts(theme=ThemeType.WESTEROS, bg_color='transparent'))
.add_schema(maptype="china", zoom=1.2, center=[105, 30])
.add("一般确诊城市", [list(z) for z in zip(cfm_city, cfm_submit)], symbol_size=6)
.add("一般确诊城市", [list(z) for z in zip(list_1, list_2)], symbol_size=6) # 孤独拉萨
.add("一般确诊城市", [list(z) for z in zip(list(serious_city), list(serious_submit))], # 感染者超1000的城市
type_=ChartType.EFFECT_SCATTER, effect_opts=opts.EffectOpts(is_show=True, color="black",
symbol_size=10, scale=3, period=1))
.add("严重城市", [list(z) for z in zip(list(serious_city), list(serious_submit))],type_=ChartType.HEATMAP)
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(
visualmap_opts=opts.VisualMapOpts(range_size=[0, 10, 50, 100, 200, 500, 50000], orient='horizontal', max_=500,is_calculable=True,
pos_bottom=0),
title_opts=opts.TitleOpts(title="中国疫情分布热图", pos_top='5%'),
legend_opts=opts.LegendOpts(pos_bottom='10%', pos_left=0)))
# 每日数据趋势
line = (
Line(init_opts=opts.InitOpts(theme=ThemeType.CHALK, bg_color="transparent"))
.add_xaxis(list(chinaDayList["date"]))
.add_yaxis("累计确诊 ", list(chinaDayList["confirm"]), is_smooth=True, yaxis_index=1)
.add_yaxis("累计死亡 ", list(chinaDayList["dead"]), is_smooth=True, yaxis_index=1)
.add_yaxis("累计治愈 ", list(chinaDayList["heal"]), is_smooth=True, yaxis_index=1)
.add_yaxis("现有疑似 ", list(chinaDayList["suspect"]), is_smooth=True, yaxis_index=1)
.add_yaxis("现有确诊 ", list(chinaDayList["nowConfirm"]), is_smooth=True, yaxis_index=1)
.add_yaxis("现有重症 ", list(chinaDayList["nowSevere"]), is_smooth=True, yaxis_index=1)
.add_yaxis("死亡率 ", list(chinaDayList["deadRate"]), is_smooth=True, yaxis_index=1)
.add_yaxis("治愈率", list(chinaDayList["healRate"]), is_smooth=True, yaxis_index=1)
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(legend_opts=opts.LegendOpts(pos_left='center')))
bar = (
Bar(init_opts=opts.InitOpts(theme=ThemeType.CHALK, bg_color="transparent"))
.add_xaxis(list(chinaDayAddList["date"]))
.add_yaxis("单日新增确诊 ", list(chinaDayAddList["confirm"]))
.add_yaxis("单日新增疑似 ", list(chinaDayAddList["suspect"]))
.add_yaxis("单日新增死亡 ", list(chinaDayAddList["dead"]))
.add_yaxis("单日新增治愈", list(chinaDayAddList["heal"]))
.extend_axis(yaxis=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter="{value}")))
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(legend_opts=opts.LegendOpts(pos_left='center'),
yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter="{value}")),
datazoom_opts=opts.DataZoomOpts())).overlap(line)
big_title = (
Pie()
.set_global_opts(
title_opts=opts.TitleOpts(title="2019-nCov",
title_textstyle_opts=opts.TextStyleOpts(font_size=40, color='#FFFFFF',
border_radius=True, border_color="white"),
pos_top=0)))
times = (
Pie()
.set_global_opts(
title_opts=opts.TitleOpts(subtitle=("截至 " + lastUpdateTime),
subtitle_textstyle_opts=opts.TextStyleOpts(font_size=13, color='#FFFFFF'),
pos_top=0))
)
# total_pie = (
# Pie(init_opts=opts.InitOpts(theme=ThemeType.LIGHT, width='500px', height='350px', bg_color="transparent"))
# .add("", [list(z) for z in zip(['累计确诊 ', '现有疑似 ', '累计死亡 ', '累计治愈 '], chinaTotal.values())],
# center=["50%", "60%"], radius=[75, 100], )
# .add("", [list(z) for z in zip(chinaAdd.keys(), chinaAdd.values())], center=["50%", "60%"], radius=[0, 50])
# .set_global_opts(title_opts=opts.TitleOpts(title="全国总量", pos_bottom=0,
# title_textstyle_opts=opts.TextStyleOpts(color="#00FFFF")),
# legend_opts=opts.LegendOpts(textstyle_opts=opts.TextStyleOpts(color="#FFFFFF")))
# .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}:{c}")))
confirms = (Pie().
set_global_opts(title_opts=opts.TitleOpts(title="确诊1", pos_left='center', pos_top='center',
title_textstyle_opts=opts.TextStyleOpts(color='#FFFFFF'))))
confirms_people = (Pie().
set_global_opts(title_opts=opts.TitleOpts(title=(str(chinaTotal['累计确诊']) + " "),
pos_top='15%', pos_left='center',
subtitle=(" 新增: " + str(chinaAdd['新增累计确诊'])),
item_gap=1,
title_textstyle_opts=opts.TextStyleOpts(color="#00FFFF",
font_size=30),
subtitle_textstyle_opts=opts.TextStyleOpts(color="#00BFFF")
)))
suspects = (Pie().
set_global_opts(title_opts=opts.TitleOpts(title="疑似1", pos_left='center', pos_top='center',
title_textstyle_opts=opts.TextStyleOpts(color='#FFFFFF'))))
suspects_people = (Pie().
set_global_opts(title_opts=opts.TitleOpts(title=(str(chinaTotal['现有疑似']) + " "),
pos_top='15%', pos_left='center',
subtitle=(" 新增 :" + str(chinaAdd['新增现有疑似'])),
item_gap=1,
title_textstyle_opts=opts.TextStyleOpts(color="#FF00FF",
font_size=30),
subtitle_textstyle_opts=opts.TextStyleOpts(color="#EE82EE")
)))
deads = (Pie().set_global_opts(title_opts=opts.TitleOpts(title="死亡1", pos_left='center', pos_top='center',
title_textstyle_opts=opts.TextStyleOpts(color='#FFFFFF'))))
deads_people = (Pie().set_global_opts(title_opts=opts.TitleOpts(title=(str(chinaTotal['累计死亡']) + " "),
pos_top='15%', pos_left='center',
subtitle=(" 新增 :" + str(chinaAdd['新增累计死亡'])),
item_gap=1,
title_textstyle_opts=opts.TextStyleOpts(color="#FF0000",
font_size=30),
subtitle_textstyle_opts=opts.TextStyleOpts(color="#F08080")
)))
heals = (Pie().set_global_opts(title_opts=opts.TitleOpts(title="治愈1", pos_left='center', pos_top='center',
title_textstyle_opts=opts.TextStyleOpts(color='#FFFFFF'))))
heals_people = (Pie().set_global_opts(title_opts=opts.TitleOpts(title=(str(chinaTotal['累计治愈']) + " "),
pos_top='15%', pos_left='center',
subtitle=(" 新增 :" + str(chinaAdd['新增累计治愈'])),
item_gap=1,
title_textstyle_opts=opts.TextStyleOpts(color="#00FF00",
font_size=30),
subtitle_textstyle_opts=opts.TextStyleOpts(color="#98FB98")
)))
confirm_liquid = (Liquid().add("确诊比例", [(chinaTotal['累计确诊'] / sum)], tooltip_opts=opts.TooltipOpts(),
label_opts=opts.LabelOpts(color="#00FFFF",
font_size=15,
formatter=JsCode(
"""function (param) {
return (Math.floor(param.value * 10000) / 100) + '%';
}"""
),
position="inside",
),
)
)
suspect_liquid = (
Liquid()
.add("疑似比例", [(chinaTotal['现有疑似'] / sum)], tooltip_opts=opts.TooltipOpts(),
label_opts=opts.LabelOpts(color="#FF00FF",
font_size=15,
formatter=JsCode(
"""function (param) {
return (Math.floor(param.value * 10000) / 100) + '%';
}"""
),
position="inside",
),
)
)
dead_liquid = (
Liquid()
.add("死亡比例", [(chinaTotal['累计死亡'] / sum)], tooltip_opts=opts.TooltipOpts(),
label_opts=opts.LabelOpts(color="#FF0000",
font_size=15,
formatter=JsCode(
"""function (param) {
return (Math.floor(param.value * 10000) / 100) + '%';
}"""
),
position="inside",
),
)
)
heal_liquid = (
Liquid()
.add("治愈比例", [(chinaTotal['累计治愈'] / sum)], tooltip_opts=opts.TooltipOpts(),
label_opts=opts.LabelOpts(color="#00FF00",
font_size=15,
formatter=JsCode(
"""function (param) {
return (Math.floor(param.value * 10000) / 100) + '%';
}"""
),
position="inside",
),
)
)
wc = (
WordCloud()
.add("", [list(z) for z in zip(list(city_data["city"]), list(city_data["confirm"]))],
word_gap=0, word_size_range=[10, 30]))
# 图片汇总
# page = (Page(page_title="2019-nCov",layout=Page.DraggablePageLayout)
page = (Page(page_title="2019-nCov")
.add(world_map)
.add(total_pie)
.add(area_map)
.add(area_heat_geo)
.add(bar)
.add(big_title)
.add(times)
.add(confirms)
.add(confirms_people)
.add(suspects)
.add(suspects_people)
.add(deads)
.add(deads_people)
.add(heals)
.add(heals_people)
.add(confirm_liquid)
.add(suspect_liquid)
.add(dead_liquid)
.add(heal_liquid)
.add(wc)
).render("2019-nCov数据一览2.html")
with open("2019-nCov数据一览2.html", "r+", encoding='utf-8') as html:
html_bf = BeautifulSoup(html, 'lxml')
divs = html_bf.select('.chart-container')
divs[0][
"style"] = "width:605px;height:274px;position:absolute;top:36px;left:333px;border-style:solid;border-color:#444444;border-width:0px;"
divs[1][
'style'] = "width:411px;height:303px;position:absolute;top:5px;left:0px;border-style:solid;border-color:#444444;border-width:0px;"
divs[2][
"style"] = "width:309px;height:405px;position:absolute;top:313px;left:961px;border-style:solid;border-color:#444444;border-width:0px;"
divs[3][
"style"] = "width:305px;height:405px;position:absolute;top:310px;left:0px;border-style:solid;border-color:#444444;border-width:0px;"
divs[4][
"style"] = "width:646px;height:304px;position:absolute;top:312px;left:312px;border-style:solid;border-color:#444444;border-width:0px;"
divs[5][
"style"] = "width:250px;height:55px;position:absolute;top:2px;left:440px;border-style:solid;border-color:#444444;border-width:0px;"
divs[6][
"style"] = "width:200px;height:30px;position:absolute;top:11px;left:675px;border-style:solid;border-color:#444444;border-width:0px;"
divs[7][
'style'] = "width:60px;height:75px;position:absolute;top:5px;left:1060px;border-style:solid;border-color:#DC143C;border-width:3px;border-radius:25px 0px 0px 0px"
divs[8][
"style"] = "width:130px;height:75px;position:absolute;top:5px;left:1120px;border-style:solid;border-color:#DC143C;border-width:3px;"
divs[9][
"style"] = "width:60px;height:75px;position:absolute;top:80px;left:1060px;border-style:solid;border-color:#DC143C;border-width:3px;"
divs[10][
"style"] = "width:130px;height:75px;position:absolute;top:80px;left:1120px;border-style:solid;border-color:#DC143C;border-width:3px;"
divs[11][
"style"] = "width:60px;height:75px;position:absolute;top:155px;left:1060px;border-style:solid;border-color:#DC143C;border-width:3px;"
divs[12][
"style"] = "width:130px;height:75px;position:absolute;top:155px;left:1120px;border-style:solid;border-color:#DC143C;border-width:3px;"
divs[13][
"style"] = "width:60px;height:75px;position:absolute;top:230px;left:1060px;border-style:solid;border-color:#DC143C;border-width:3px;"
divs[14][
"style"] = "width:130px;height:75px;position:absolute;top:230px;left:1120px;border-style:solid;border-color:#DC143C;border-width:3px;border-radius:0px 0px 25px 0px"
divs[15][
"style"] = "width:160px;height:160px;position:absolute;top:-35px;left:920px;border-style:solid;border-color:#444444;border-width:0px;"
divs[16][
"style"] = "width:160px;height:160px;position:absolute;top:40px;left:865px;border-style:solid;border-color:#444444;border-width:0px;"
divs[17][
"style"] = "width:160px;height:160px;position:absolute;top:115px;left:920px;border-style:solid;border-color:#444444;border-width:0px;"
divs[18][
"style"] = "width:160px;height:160px;position:absolute;top:188px;left:865px;border-style:solid;border-color:#444444;border-width:0px;"
divs[19][
"style"] = "width:1280px;height:120px;position:absolute;top:600px;left:0px;border-style:solid;border-color:#444444;border-width:0px;"
body = html_bf.find("body")
body["style"] = "background-color:#333333;"
print('$$$$$$$$$$$$$$$$$$$$$')
html_new = str(html_bf)
html.seek(0, 0)
html.truncate()
print('???????????')
html.write(html_new)
# make_snapshot(snapshot, '2019-nCov数据一览2.html', "2019-nCoV数据一览2.png")
html.close()