|
|
|
@ -1,9 +1,10 @@
|
|
|
|
|
import requests
|
|
|
|
|
import re
|
|
|
|
|
import time
|
|
|
|
|
import datetime
|
|
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
import lxml
|
|
|
|
|
import json
|
|
|
|
|
import pymysql
|
|
|
|
|
|
|
|
|
|
class summary_cn:
|
|
|
|
|
def __init__(self):
|
|
|
|
@ -28,6 +29,30 @@ class summary_cn:
|
|
|
|
|
self.curConfirmRelative = 0
|
|
|
|
|
self.icuDisable = 0
|
|
|
|
|
self.mapLastUpdatedTime = 0
|
|
|
|
|
def get_db_tuple(self):
|
|
|
|
|
return (self.confirmed,self.died,self.cured,self.asymptomatic,self.asymptomaticRelative,
|
|
|
|
|
self.unconfirmed,self.relativeTime,self.confirmedRelative,self.unconfirmedRelative,
|
|
|
|
|
self.curedRelative,self.diedRelative,self.icu,self.icuRelative,self.overseasInput,
|
|
|
|
|
self.unOverseasInputCumulative,self.overseasInputRelative,self.unOverseasInputNewAdd,
|
|
|
|
|
self.curConfirm,self.curConfirmRelative,self.icuDisable,self.mapLastUpdatedTime,
|
|
|
|
|
datetime.datetime.now().strftime('%Y-%m-%d'))
|
|
|
|
|
def insert_sql(con):
|
|
|
|
|
sql='''
|
|
|
|
|
insert into cn_sunmary(confirmed,died,cured,asymptomatic,asymptomaticRelative,
|
|
|
|
|
unconfirmed,relativeTime,confirmedRelative,unconfirmedRelative,
|
|
|
|
|
curedRelative,diedRelative,icu,icuRelative,overseasInput,
|
|
|
|
|
unOverseasInputCumulative,overseasInputRelative,unOverseasInputNewAdd,
|
|
|
|
|
curConfirm,curConfirmRelative,icuDisable,mapLastUpdatedTime,InsertTime) values(%d,%d,%d,
|
|
|
|
|
%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%s)
|
|
|
|
|
'''
|
|
|
|
|
try:
|
|
|
|
|
con.cursor().execute(sql,self.get_db_tuple())
|
|
|
|
|
con.commit()
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(e)
|
|
|
|
|
print('Insert failed.')
|
|
|
|
|
else:
|
|
|
|
|
print('Inserted successfully')
|
|
|
|
|
def __str__(self):
|
|
|
|
|
string = '截止' + self.mapLastUpdatedTime + '\n'
|
|
|
|
|
string+= "国内现有\n\t确诊:" + str(self.curConfirm) + '\t较昨日' + str(self.curConfirmRelative)
|
|
|
|
@ -68,11 +93,10 @@ def getCnSummary():
|
|
|
|
|
sum.curConfirmRelative = int(ans['curConfirmRelative'])
|
|
|
|
|
sum.icuDisable = int(ans['icuDisable'])
|
|
|
|
|
sum.mapLastUpdatedTime = tagjs['component'][0]['mapLastUpdatedTime']
|
|
|
|
|
print(sum)
|
|
|
|
|
#print(sum)
|
|
|
|
|
return sum
|
|
|
|
|
|
|
|
|
|
def getCnNews():
|
|
|
|
|
from selenium import webdriver
|
|
|
|
|
b = webdriver.Chrome()
|
|
|
|
|
b.get("https://voice.baidu.com/act/newpneumonia/newpneumonia")
|
|
|
|
|
txt = b.page_source
|
|
|
|
@ -90,5 +114,5 @@ def getCnNews():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
#undefined_D()
|
|
|
|
|
#getCnNews()
|
|
|
|
|
getCnSummary()
|
|
|
|
|
|
|
|
|
|