一直出现那个错误
def close_conn(conn, cursor):
if cursor:
cursor.close()
if conn:
conn.close()
def update_details(url_today):
cursor = None
conn = None
try:
detail_data = get_today(url_today)
conn, cursor = get_conn()
sql = "insert into details(update_time,province,city,confirm,confirm_add,heal,dead) values(%s,%s,%s,%s,%s,%s,%s)"
sql_query = 'select %s=(select update_time from details order by id desc limit 1)'
cursor.execute(sql_query, detail_data[0][0])
if not cursor.fetchone()[0]:
print(f"{time.asctime()}开始更新最新数据")
for item in detail_data:
cursor.execute(sql, item)
conn.commit() # 提交事务 update delete insert操作
print(f"{time.asctime()}更新最新数据完毕")
else:
print(f"{time.asctime()}已是最新数据!")
except:
traceback.print_exc()
finally:
close_conn(conn, cursor)
def insert_history(url_history):
cursor = None
conn = None
try:
dic = get_history(url_history)
print(f'{time.asctime()}开始插入历史数据')
conn, cursor = get_conn()
sql = "insert into history values(%s,%s,%s,%s,%s,%s,%s,%s,%s)"
for key, value in dic.items():
cursor.execute(sql, [key, value.get("confirm"), value.get("confirm_add"), value.get("suspect"),
value.get("suspect_add"), value.get("heal"), value.get("heal_add"),
value.get("dead"), value.get("dead_add")])
conn.commit()
print(f"{time.asctime()}插入历史数据完毕")
except:
traceback.print_exc()
finally:
close_conn(conn, cursor)
def update_history(url_history):
cursor = None
conn = None
try:
dic = get_history(url_history)
print(f"{time.asctime()}开始更新历史数据")
conn, cursor = get_conn()
sql = "insert into history values(%s,%s,%s,%s,%s,%s,%s,%s,%s)"
sql_query = "select confirm from" \
"history where ds=&s"
for key, value in dic.items():
if not cursor.execute(sql_query, key):
cursor.execute(sql, [key, value.get("confirm"), value.get("confirm_add"), value.get("suspect"),
value.get("suspect_add"), value.get("heal"), value.get("heal_add"),
value.get("dead"), value.get("dead_add")])
conn.commit()
print(f"{time.asctime()}历史数据更新完毕")
except:
traceback.print_exc()
finally:
close_conn(conn, cursor)
def update_world(url_world):
cursor = None
conn = None
try:
list = get_world(url_world)
print(f"{time.asctime()}开始更新历史数据")
conn, cursor = get_conn()
sql = "TRUNCATE TABLE world"
cursor.execute(sql)
sql = "insert into world values(%s,%s)"
for i in list:
cursor.execute(sql,[(i[0]),(i[1])])
sqll ="SELECT confirm FROM history ORDER BY ds DESC LIMIT 1"
cursor.execute(sqll)
nu = cursor.fetchall()
dat =int(nu[0][0])
cursor.execute(sql,[('中国'),(dat)])
conn.commit()
print(f"{time.asctime()}历史数据更新完毕")
except:
traceback.print_exc()
finally:
close_conn(conn, cursor)
if __name__ == '__main__':
print(get_history(url_history))
print(get_today(url_today))
insert_history(url_history)
print(get_world(url_world))
update_details(url_today)
update_history(url_history)
update_world(url_world)
TypeError: not all arguments converted during string formatting
怀疑是数据库字符设置的不合适
结课求帮助