国内疫情实时概况

zhousufan
Your Namehzh 4 years ago
parent 905398cfeb
commit e6f44ca00c

@ -1 +0,0 @@
111

@ -0,0 +1,79 @@
import pymysql
import requests
from bs4 import BeautifulSoup
import json
import re
import pymysql
def getData(DB):
cs = DB.cursor()
cs.execute('select * from cn')
res = cs.fetchone()
print(res)
def delData(DB,day):
cs = DB.cursor()
tmp = day[0:11:1] +'%'
sql = 'delete from cn where date like %s'
data = [tmp]
try:
cs.executemany(sql,data)
DB.commit()
except Exception as e:
print('删除不成功')
print(e)
def fun1(summary):
tmp = summary.__dict__
d = []
for item in tmp:
d.append(tmp[item])
return d
def save_summary(host,user, password, database):
#db = pymysql.connect('localhost', 'root', '123456', 'covid19')
db = pymysql.connect(host,user, password, database)
cs = db.cursor()
tmp,time = Mod_Summary_CN()
D = fun1(tmp)
tmp1 = []
for i in range(0,18):
tmp1.append(D[i])
tmp1.append(time)
tmp2 = tuple(tmp1)
sql = 'insert into cn(confirmed, confirmed_R, curConfirm, curConfirm_R, died, died_R,cured, cured_R, asymptomatic, asymptomatic_R, unconfirmed, \
unconfirmed_R, icu, icu_R, overseasIn, overseasIn_R, unOverseasInC, unOverseasInA, date)values(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)'
data = []
data.append(tmp2)
try:
delData(db,time)
cs.executemany(sql,data)
except Exception as e:
print('添加不成功')
print(e)
else:
db.commit()
print('添加成功')
getData(db)
cs.close()
db.close()

@ -0,0 +1,50 @@
import requests
from bs4 import BeautifulSoup
import json
import re
def Mod_Summary_CN():
response = requests.get('https://voice.baidu.com/act/newpneumonia/newpneumonia/')
content = response.text
soup = BeautifulSoup(content, 'html.parser')
tag1 = soup.find('script', attrs={'id':'captain-config'})
tagstr = str(tag1)
res = re.findall(r'(\{".*?".*?\})',tagstr)
tagJson = json.loads(res[831])
temp1 = re.findall(r'("mapLastUpdatedTime":".*?")',tagstr)
temp2 = str(temp1[0])
time = temp2[22:len(temp2)-1:1]
summary = Summary()
summary.confirmed = int(tagJson['confirmed'])
summary.confirmedRelative = int(tagJson['confirmedRelative'])
summary.curConfirm = int(tagJson['curConfirm'])
summary.curConfirmRelative = int(tagJson['curConfirmRelative'])
summary.died = int(tagJson['died'])
summary.diedRelative = int(tagJson['diedRelative'])
summary.cured = int(tagJson['cured'])
summary.curedRelative = int(tagJson['curedRelative'])
summary.asymptomatic = int(tagJson['asymptomatic'])
summary.asymptomaticRelative = int(tagJson['asymptomaticRelative'])
summary.unconfirmed = int(tagJson['unconfirmed'])
summary.unconfirmedRelative = int(tagJson['unconfirmedRelative'])
summary.icu = int(tagJson['icu'])
summary.icuRelative = int(tagJson['icuRelative'])
summary.overseasInput = int(tagJson['overseasInput'])
summary.overseasInputRelative = int(tagJson['overseasInputRelative'])
summary.unOverseasInputCumulative = int(tagJson['unOverseasInputCumulative'])
summary.unOverseasInputNewAdd = int(tagJson['unOverseasInputNewAdd'])
summary.icuDisable = int(tagJson['icuDisable'])
#print('---------------------------------------------------------')
#print(' 更新时间:%s'%(time))
#print('---------------------------------------------------------')
#print(summary)

@ -0,0 +1,30 @@
class Summary:
import time
def __init__(self):
self.confirmed = 0
self.confirmedRelative = 0
self.curConfirm = 0
self.curConfirmRelative = 0
self.died = 0
self.diedRelative = 0
self.cured = 0
self.curedRelative = 0
self.asymptomatic = 0
self.asymptomaticRelative = 0
self.unconfirmed = 0
self.unconfirmedRelative = 0
self.icu = 0
self.icuRelative = 0
self.overseasInput = 0
self.overseasInputRelative = 0
self.unOverseasInputCumulative = 0
self.unOverseasInputNewAdd = 0
self.icuDisable = 0
def __str__(self):
return '\n累计确诊%d\n累计确诊增加%d\n现有确诊%d\n新增确诊较昨日%d\n累计死亡%d\n新增死亡%d\n累计治愈%d\n新增治愈%d\n\
累计无症状感染者:%d\n新增无症状感染者%d\n现有疑似%d\n新增疑似%d\n现有重症%d\n新增重症%d\n累计境外输入%d\n\
新增境外输入:%d\n累计非境外输入的确诊%d\n非境外输入的新增确诊%d\n%d'\
%(self.confirmed,self.confirmedRelative,self.curConfirm,self.curConfirmRelative,self.died,self.diedRelative,self.cured,self.curedRelative,self.asymptomatic,self.asymptomaticRelative,self.unconfirmed,self.unconfirmedRelative,self.icu,self.icuRelative,self.overseasInput,self.overseasInputRelative,self.unOverseasInputCumulative,self.unOverseasInputNewAdd,self.icuDisable)

@ -0,0 +1,31 @@
【summaryDataIn】
"confirmed" 累计确诊:%d\n
"confirmedRelative" 累计确诊增加:%d\n
"curConfirm": 现有确诊:%d\n
"curConfirmRelative": 新增确诊(较昨日):%d\n
"died" 累计死亡:%d\n
"diedRelative" 新增死亡:%d\n
"cured" 累计治愈:%d\n
"curedRelative" 新增治愈:%d\n
"asymptomatic" 累计无症状感染者:%d\n
"asymptomaticRelative" 新增无症状感染者:%d\n
"unconfirmed" 现有疑似:%d\n
"unconfirmedRelative" 新增疑似:%d\n
"icu": 现有重症:%d\n
"icuRelative" 新增重症:%d\n
"overseasInput" 累计境外输入:%d\n
"overseasInputRelative" 新增境外输入:%d\n
"unOverseasInputCumulative" 累计非境外输入的确诊:%d\n
"unOverseasInputNewAdd" 非境外输入的新增确诊:%d\n
"relativeTime" 时间:%d\n
"icuDisable"
Loading…
Cancel
Save