|
|
|
@ -11,6 +11,12 @@ class MyDB:
|
|
|
|
|
info_tuple.append(item.get_info_tuple())
|
|
|
|
|
return info_tuple
|
|
|
|
|
|
|
|
|
|
def get_city_list_tuple(self):
|
|
|
|
|
city_info_tuple = []
|
|
|
|
|
for city in self.subList:
|
|
|
|
|
city_info_tuple.append((city.city,city.confirmedRelative,city.confirmed,city.died,city.crued,city.pub_date,city.province))
|
|
|
|
|
return city_info_tuple
|
|
|
|
|
|
|
|
|
|
# 保存省份数据
|
|
|
|
|
def save_province_datas(self, all_provinces):
|
|
|
|
|
curdate = all_provinces[0].pub_date
|
|
|
|
@ -33,6 +39,33 @@ class MyDB:
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(e)
|
|
|
|
|
print('+++ save_province_datas is over.')
|
|
|
|
|
|
|
|
|
|
# 保存地级市数据
|
|
|
|
|
def save_city_datas(self, all_provinces):
|
|
|
|
|
curdate = all_provinces[0].pub_date
|
|
|
|
|
sql = 'delete from city_daily_datas where pub_date like "%s"'%(curdate[:10] + '%')
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
self.cursor.execute(sql)
|
|
|
|
|
self.conn.commit()
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sql = 'insert into city_daily_datas(city,confirmedRelative,curConfirm,confirmed,died,crued,pub_date,province) values(%s,%s,%s,%s,%s,%s,%s,%s)'
|
|
|
|
|
res = all_city_infos = []
|
|
|
|
|
for province in all_provinces:
|
|
|
|
|
city_info = province.get_city_info_tuple()
|
|
|
|
|
all_city_infos += city_info
|
|
|
|
|
|
|
|
|
|
print('+++ save_city_datas, data len: %d' % len(res))
|
|
|
|
|
try:
|
|
|
|
|
self.cursor.executemany(sql, res)
|
|
|
|
|
self.conn.commit()
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(e)
|
|
|
|
|
print('+++ save_city_datas is over.')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __del__(self):
|
|
|
|
|