You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
2.1 KiB
104 lines
2.1 KiB
import spider as sp
|
|
import requests,json
|
|
|
|
from pymysql import *
|
|
def connectDB():
|
|
try:
|
|
db = connect(host='localhost', port=3306, user='root', password='759521', db='FeiYan')
|
|
print("数据库连接成功")
|
|
return db
|
|
except Exception as e:
|
|
print(e)
|
|
return
|
|
|
|
|
|
db=connectDB()
|
|
|
|
def update_foreign_table():
|
|
youbiao=db.cursor()
|
|
sql='truncate country'
|
|
try:
|
|
youbiao.execute(sql)
|
|
db.commit()
|
|
print('success')
|
|
except Exception as e:
|
|
print(e)
|
|
sp.spider_foreign()
|
|
return
|
|
def update_city_table():
|
|
youbiao = db.cursor()
|
|
sql = 'truncate city'
|
|
try:
|
|
youbiao.execute(sql)
|
|
db.commit()
|
|
print('success')
|
|
except Exception as e:
|
|
print(e)
|
|
sp.spider_city()
|
|
return
|
|
|
|
|
|
def update_rumor_table():
|
|
youbiao = db.cursor()
|
|
sql = 'truncate rumor'
|
|
try:
|
|
youbiao.execute(sql)
|
|
db.commit()
|
|
print('success')
|
|
except Exception as e:
|
|
print(e)
|
|
sp.spider_rumor()
|
|
return
|
|
def update_hospital_table():
|
|
youbiao = db.cursor()
|
|
sql = 'truncate hospital'
|
|
try:
|
|
youbiao.execute(sql)
|
|
db.commit()
|
|
print('success')
|
|
except Exception as e:
|
|
print(e)
|
|
sp.spider_hospital()
|
|
return
|
|
|
|
|
|
def DB_ctr(sql):
|
|
|
|
dbb = connectDB()
|
|
aa=dbb.cursor()
|
|
aa.execute(sql)
|
|
res = aa.fetchall()
|
|
#aa.close()
|
|
#db.close()
|
|
return res
|
|
def get_c1_data():
|
|
|
|
sql="SELECT SUM(now_confirm),SUM(dead),SUM(confirm),(SELECT SUM(confirm) from city where name = '境外输入')"\
|
|
"FROM city"
|
|
aa=DB_ctr(sql)
|
|
return aa[0]
|
|
def get_r1_data():
|
|
|
|
sql="SELECT SUM(now_confirm),sum(dead),SUM(confirm)"\
|
|
"FROM country"
|
|
aa=DB_ctr(sql)
|
|
return aa[0]
|
|
def get_world_data():
|
|
sql="select `name`,now_confirm FROM country"
|
|
aa=DB_ctr(sql)
|
|
ll=[]
|
|
for i in aa:
|
|
dd={"name":i[0],"now_confirm":i[1]}
|
|
ll.append(dd)
|
|
xx=str(ll)
|
|
c=xx.replace("'","\"")
|
|
d="\"nicai\""+":"+c
|
|
return d
|
|
|
|
|
|
|
|
def chushihua():
|
|
sp.chushihua_prov()
|
|
sp.chushihua_dazhou()
|
|
return
|