add truncate

This commit is contained in:
lwl0608 2024-09-18 22:05:29 +08:00
parent 544afeb0ac
commit 920245cd92
1 changed files with 13 additions and 8 deletions

View File

@ -46,6 +46,11 @@ class S:
print("len(rows): {}".format(len(rows)))
sort_dict_list(rows, "income", desc=True)
# 清理表
sql = "truncate table vas_cur_streamer_income"
ret = self.mysql_db_bi.exec(sql, ())
print("truncate finish, ret: {}".format(ret))
dt = datetime.datetime.fromtimestamp(st)
formatted_dt = dt.strftime('%Y-%m-%d 00:00:00')
idx = 0
@ -56,12 +61,12 @@ class S:
mid = safe_get_int(row, "mid")
income = safe_get_int(row, "income")
sql_q = "select * from vas_cur_streamer_income where mid={} and pdate='{}'".format(mid, formatted_dt)
rows_bi = self.mysql_db_bi.query(sql_q)
if len(rows_bi) > 0:
sql_u = "update vas_cur_streamer_income set income=%s where mid=%s and pdate=%s"
self.mysql_db_bi.exec(sql_u, (income, mid, formatted_dt))
else:
# sql_q = "select * from vas_cur_streamer_income where mid={} and pdate='{}'".format(mid, formatted_dt)
# rows_bi = self.mysql_db_bi.query(sql_q)
# if len(rows_bi) > 0:
# sql_u = "update vas_cur_streamer_income set income=%s where mid=%s and pdate=%s"
# self.mysql_db_bi.exec(sql_u, (income, mid, formatted_dt))
# else:
sql_i = "insert into vas_cur_streamer_income (mid, pdate, income) values (%s,%s,%s)"
self.mysql_db_bi.exec(sql_i, (mid, formatted_dt, income))