完成信息存储功能

master
yangxudongll 5 years ago
parent 262e968fb7
commit fffe76ee5a

@ -2,8 +2,10 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="fcea9d71-f4b2-41ab-b680-ecae8402b966" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/xinguan.sql" beforeDir="false" afterPath="$PROJECT_DIR$/xinguan.sql" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../数据采集/百度数据/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../数据采集/百度数据/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/DataFrame.py" beforeDir="false" afterPath="$PROJECT_DIR$/DataFrame.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/GrapData.py" beforeDir="false" afterPath="$PROJECT_DIR$/GrapData.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Grapmain.py" beforeDir="false" afterPath="$PROJECT_DIR$/Grapmain.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -78,22 +80,22 @@
<servers />
</component>
<component name="WindowStateProjectService">
<state width="1814" height="387" key="GridCell.Tab.0.bottom" timestamp="1596607121816">
<state width="1814" height="241" key="GridCell.Tab.0.bottom" timestamp="1596610032433">
<screen x="67" y="27" width="1853" height="1053" />
</state>
<state width="1814" height="387" key="GridCell.Tab.0.bottom/67.27.1853.1053@67.27.1853.1053" timestamp="1596607121816" />
<state width="1814" height="387" key="GridCell.Tab.0.center" timestamp="1596607121816">
<state width="1814" height="241" key="GridCell.Tab.0.bottom/67.27.1853.1053@67.27.1853.1053" timestamp="1596610032433" />
<state width="1814" height="241" key="GridCell.Tab.0.center" timestamp="1596610032431">
<screen x="67" y="27" width="1853" height="1053" />
</state>
<state width="1814" height="387" key="GridCell.Tab.0.center/67.27.1853.1053@67.27.1853.1053" timestamp="1596607121816" />
<state width="1814" height="387" key="GridCell.Tab.0.left" timestamp="1596607121816">
<state width="1814" height="241" key="GridCell.Tab.0.center/67.27.1853.1053@67.27.1853.1053" timestamp="1596610032431" />
<state width="1814" height="241" key="GridCell.Tab.0.left" timestamp="1596610032430">
<screen x="67" y="27" width="1853" height="1053" />
</state>
<state width="1814" height="387" key="GridCell.Tab.0.left/67.27.1853.1053@67.27.1853.1053" timestamp="1596607121816" />
<state width="1814" height="387" key="GridCell.Tab.0.right" timestamp="1596607121816">
<state width="1814" height="241" key="GridCell.Tab.0.left/67.27.1853.1053@67.27.1853.1053" timestamp="1596610032430" />
<state width="1814" height="241" key="GridCell.Tab.0.right" timestamp="1596610032432">
<screen x="67" y="27" width="1853" height="1053" />
</state>
<state width="1814" height="387" key="GridCell.Tab.0.right/67.27.1853.1053@67.27.1853.1053" timestamp="1596607121816" />
<state width="1814" height="241" key="GridCell.Tab.0.right/67.27.1853.1053@67.27.1853.1053" timestamp="1596610032432" />
<state x="1111" y="25" key="search.everywhere.popup" timestamp="1596606706048">
<screen x="67" y="27" width="1853" height="1053" />
</state>

@ -139,6 +139,7 @@ class SaveToDB():
curser.close()
self.conn.close()
#存储国内各省疫情信息
def InsertIntoProvince(self,data):
#param data list(tuple),每个元组即一个省的信息
#首先删掉数据库中当日的数据
@ -156,6 +157,7 @@ class SaveToDB():
cursor.execute(sql)
cursor.close()
#存储国内城市的疫情信息
def InsertToCity(self,data):
#首先删掉数据库中当日的数据
cursor=self.conn.cursor()
@ -171,6 +173,7 @@ class SaveToDB():
cursor.execute(sql)
cursor.close()
#存储外国所有国家疫情信息
def InsertForeignCountry(self,data):
#首先删掉数据库中当日的数据
cursor=self.conn.cursor()
@ -189,6 +192,39 @@ class SaveToDB():
pass
cursor.close()
#存储国内疫情汇总
def InsertSummaryChina(self,data):
# 首先删掉数据库中当日的数据
cursor = self.conn.cursor()
insertTime = data[-1]
# 删掉同一天的数据
deletesql = 'delete from InsideChina where Date(updateTime)=Date("%s");' % (insertTime)
cursor.execute(deletesql)
# 设置ID从最小开始
self.__rule('InsideChina')
sql = 'insert into InsideChina(curConfirm,curConfirmRelative,asymptomatic,asymptomaticRelative,' \
'unconfirmed,unconfirmedRelative,icu,icuRelative,confirmed,confirmedRelative,' \
'overseasInput,overseasInputRelative,cured,curedRelative,died,diedRelative,updateTime) ' \
'values(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,"%s");' % (data)
cursor.execute(sql)
cursor.close()
#存储国外疫情汇总
def InsertSummaryForeign(self,data):
# 首先删掉数据库中当日的数据
cursor = self.conn.cursor()
insertTime = data[-1]
# 删掉同一天的数据
deletesql = 'delete from OutsideChina where Date(updateTime)=Date("%s");' % (insertTime)
cursor.execute(deletesql)
# 设置ID从最小开始
self.__rule('OutsideChina')
sql = 'insert into OutsideChina(confirmed,curConfirmed,confirmedRelative,' \
'cured,curedRelative,died,diedRelative,updateTime) ' \
'values(%d,%d,%d,%d,%d,%d,%d,"%s");' % (data)
cursor.execute(sql)
cursor.close()
#删除某些元组后ID可能出现中断手动调整ID连续从最小ID开始

@ -148,6 +148,9 @@ class Spider():
Outside.diedRelative=int(DataOut['diedRelative'])
Outside.updatedTime=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
print(Outside)
return (Outside.confirmed,Outside.curConfirm,Outside.confirmedRelative,
Outside.cured,Outside.curedRelative,Outside.died,Outside.diedRelative,
Outside.updatedTime)
#抓取国内疫情信息概况
@ -183,6 +186,11 @@ class Spider():
Inside.curConfirmRelative=int(DataIn['curConfirmRelative'])
Inside.updatedTime=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
print(Inside)
return (Inside.curConfirm,Inside.curConfirmRelative,Inside.asymptomatic,Inside.asymptomaticRelative,
Inside.unconfirmed,Inside.unconfirmedRelative,Inside.icu,Inside.icuRelative,Inside.confirmed,
Inside.confirmedRelative,Inside.overseasInput,Inside.overseasInputRelative,Inside.cured,
Inside.curConfirmRelative,Inside.died,Inside.diedRelative,Inside.updatedTime)
def dealData(self,a,b):

@ -3,10 +3,14 @@ from GrapData import Spider,SaveToDB
def main():
spider=Spider()
spider.url='https://voice.baidu.com/act/newpneumonia/newpneumonia/'
spider.grapProvince()
#spider.grapProvince()
savedb=SaveToDB()
foreignData=spider.grapForeign()
savedb.InsertForeignCountry(foreignData)
#foreignData=spider.grapForeign()
#国内疫情概述
#InsideData=spider.grapSummaryChina()
#国外疫情汇总
OutsideData=spider.grapSummaryForeign()
savedb.InsertSummaryForeign(OutsideData)
if __name__ == '__main__':
main()
Loading…
Cancel
Save