zhousufan
parent
bf33c4c197
commit
413b23825d
@ -1,79 +0,0 @@
|
||||
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()
|
||||
|
||||
|
@ -1,50 +0,0 @@
|
||||
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)
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue