-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,393 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#-*- coding = utf-8 -*- | ||
#@Time : XXXXXXXXXXXXXX | ||
#@Author : shy-2 | ||
#@File : data_get.py | ||
#@Software : PyCharm | ||
|
||
import requests | ||
from lxml import etree | ||
import re | ||
import json | ||
|
||
class Get_data(): | ||
#获取数据 | ||
def get_data(self): | ||
response = requests.get('https://voice.baidu.com/act/newpneumonia/newpneumonia/?from=osari_pc_3') | ||
with open('html.txt','w') as file: | ||
file.write(response.text) | ||
|
||
#提取更新时间 | ||
def get_time(self): | ||
with open('html.txt','r') as file: | ||
text = file.read() | ||
time = re.findall('"mapLastUpdatedTime":"(.*?)"',text)[0] | ||
# print(time) | ||
return time | ||
|
||
#解析数据 | ||
def parse_data(self): | ||
with open('html.txt','r') as file: | ||
text = file.read() | ||
html = etree.HTML(text) | ||
result = html.xpath('//script[@type="application/json"]/text()') | ||
# print(result) | ||
result = result[0] | ||
result = json.loads(result) | ||
result = result['component'][0]['caseList'] | ||
result = json.dumps(result) | ||
with open("data.json",'w') as file: | ||
file.write(result) | ||
print("数据写入成功……") | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#-*- coding = utf-8 -*- | ||
#@Time : XXXXXXXXXXXXXXXX | ||
#@Author : shy-2 | ||
#@File : data_more.py | ||
#@Software : PyCharm | ||
|
||
import json | ||
import map_draw | ||
import data_get | ||
|
||
with open("data.json",'r') as file: | ||
data = file.read() | ||
data = json.loads(data) | ||
|
||
# print(data) | ||
|
||
map = map_draw.Draw_map() | ||
datas = data_get.Get_data() | ||
datas.get_data() | ||
update_time = datas.get_time() | ||
datas.parse_data() | ||
|
||
#中国疫情地图数据 | ||
def china_map(): | ||
area = [] | ||
confirmed = [] | ||
for each in data: | ||
# print(each) | ||
# print('*'*50+'\n') | ||
area.append(each['area']) | ||
confirmed.append(each['confirmed']) | ||
# print(area) | ||
# print(confirmed) | ||
map.to_map_china(area,confirmed,update_time) | ||
|
||
#省份疫情数据 | ||
def province_map(): | ||
for each in data: | ||
city = [] | ||
confirmeds = [] | ||
province = each['area'] | ||
for each_city in each['subList']: | ||
city.append(each_city['city']) | ||
confirmeds.append(each_city['confirmed']) | ||
|
||
# print(city) | ||
# print(confirmeds) | ||
|
||
china_map() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#-*- coding = utf-8 -*- | ||
#@Time : XXXXXXXXXXXXXXXX | ||
#@Author : shy-2 | ||
#@File : get_data.py | ||
#@Software : PyCharm | ||
|
||
import requests | ||
from lxml import etree | ||
import json | ||
import openpyxl | ||
|
||
url = 'https://voice.baidu.com/act/newpneumonia/newpneumonia/?from=osari_pc_3' | ||
response = requests.get(url) | ||
# print(response.text) | ||
|
||
#生成HTML对象 | ||
html = etree.HTML(response.text) | ||
result = html.xpath('//script[@type="application/json"]/text()') | ||
# print(type(result)) #list | ||
# print(result[0]) #将列表中的内容提取出来 是一个字符串 | ||
result = result[0] | ||
|
||
#将字符串转换成字典 | ||
result = json.loads(result) | ||
# print(type(result)) #dict | ||
|
||
# print(result['component'][0]['caseList']) | ||
|
||
#创建一个工作簿 | ||
wb = openpyxl.Workbook() | ||
#创建一个工作表 | ||
ws = wb.active | ||
ws.title = "国内疫情" | ||
ws.append(['省份','累计确诊','死亡','治愈','现有确诊','累计确诊增量','死亡增量','治愈增量','现有确诊增量']) | ||
|
||
# 国内 result_in | ||
#国外 result_out | ||
result_in = result['component'][0]['caseList'] | ||
result_out = result['component'][0]['globalList'] | ||
for each in result_in: | ||
# print(each) | ||
# print('*'*50+'\n') | ||
temp_list = [each['area'],each['confirmed'],each['died'],each['crued'],each['curConfirm'],each['confirmedRelative'], | ||
each['diedRelative'],each['curedRelative'],each['curConfirmRelative']] | ||
for i in range(len(temp_list)): | ||
if temp_list[i] == '': | ||
temp_list[i] = '0' | ||
ws.append(temp_list) | ||
|
||
for each in result_out: | ||
# print(each) | ||
# print('*'*50+'\n') | ||
sheet_title = each['area'] | ||
# 创建新的工作表 | ||
ws_out = wb.create_sheet(sheet_title) | ||
ws_out.append(['国家','累计确诊','死亡','治愈','现有确诊','累计确诊增量']) | ||
for country in each['subList']: | ||
temp_list = [country['country'],country['confirmed'],country['died'],country['crued'],country['curConfirm'],country['confirmedRelative']] | ||
for i in range(len(temp_list)): | ||
if temp_list[i] == '': | ||
temp_list[i] = '0' | ||
ws_out.append(temp_list) | ||
|
||
wb.save("./data.xlsx") | ||
''' | ||
area --> 省份/直辖市/特别行政区 | ||
city --> 城市 | ||
confirmed --> 累计确诊人数 | ||
died --> 死亡人数 | ||
crued --> 治愈人数 | ||
confirmedRelative --> 累计确诊的增量 | ||
cruedRelative --> 治愈的增量 | ||
curConfirm --> 现有的确诊人数 | ||
curConfirmRelative --> 现有的确诊的增量 | ||
diedRelative --> 死亡的增量 | ||
''' | ||
|
||
|
||
|
Oops, something went wrong.