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.

71 lines
1.9 KiB

import time
import pymysql
def get_time():
time_str= time.strftime("%Y{}%m{}%d{} %X")
return time_str.format("","","")
pass
def get_conn():
conn =pymysql.connect(host="localhost",
user="root",
password="130031",
db="cov2019",
charset="utf8" )
cursor=conn.cursor()
return conn,cursor
def close_conn(conn,cursor):
cursor.close()
conn.close()
def query(sql,*args):
conn,cursor=get_conn()
cursor.execute(sql,args)
res=cursor.fetchall()
close_conn(conn,cursor)
return res
def get_m1_data():
sql="select sum(现有确诊),sum(累计确诊),sum(疑似病例),sum(累计死亡),sum(累计治愈)" \
"from chinadetail " \
"where 日期=(select 日期 from chinadetail order by 日期 desc limit 1)"
res=query(sql)
return res[0]
def get_m2_data():
sql="select 省名,sum(累计确诊)" \
"from chinadetail " \
"where 日期=(select 日期 from chinadetail order by 日期 desc limit 1)" \
"group by 省名"
res=query(sql)
return res
def get_l1_data():
sql="select 日期,现有确诊,累计确诊,累计死亡,累计治愈 from chinatotal "
res=query(sql)
return res
def get_r1_data():
sql="select * from (select 省名,sum(现有确诊) a from chinadetail where 日期=(select 日期 from chinadetail order by 日期 desc limit 1)" \
"group by 省名 order by a desc)r" \
"where limit 5"
res=query(sql)
return res
def get_r2_data():
sql="select sum(现有确诊),sum(累计确诊),sum(疑似病例),sum(累计死亡),sum(累计治愈)" \
"from chinadetail " \
"where 日期=(select 日期 from chinadetail order by 日期 desc limit 1)"
res=query(sql)
return res[0]
if __name__ == '__main__':
print(get_time())
print(get_r1_data())