From 62184e8ad82e87e2322d35429bc3684e98655ffd Mon Sep 17 00:00:00 2001 From: Franklin-F Date: Tue, 20 May 2025 21:12:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=8F=92=E5=85=A5=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=20ON=20DUPLICATE=20KEY=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=8E=B0=E6=9C=89=E8=AE=B0=E5=BD=95=E4=BB=A5=E6=8F=90=E9=AB=98?= =?UTF-8?q?=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DB.py | 66 ++++++++++++++++++++--------------------------------------- 1 file changed, 22 insertions(+), 44 deletions(-) diff --git a/DB.py b/DB.py index 75a8aa1..1edf1de 100644 --- a/DB.py +++ b/DB.py @@ -229,21 +229,6 @@ class DBVidcon: while True: try: - # 1) 先读 is_repeat - select_repeat = """ - SELECT is_repeat,watch_number,follow_number,video_number - FROM sh_dm_video_v2 - WHERE rn = %(rn)s - AND v_xid = %(v_xid)s - LIMIT 1 - """ - self.cursor.execute(select_repeat, data) - row = self.cursor.fetchone() - if row: - data['is_repeat'] = row.get('is_repeat', 3) - data['fans'] = row.get('follow_number', 0) - data['videos'] = row.get('video_number', 0) - # 2) 插入到 op 表 sql_op = """ INSERT INTO sh_dm_video_op_v2 ( v_id, v_xid, a_id, level, name_title, @@ -256,36 +241,29 @@ class DBVidcon: ) """ self.cursor.execute(sql_op, data) + sql_update = """ + INSERT INTO sh_dm_video_v2 ( + v_id, v_xid, rn, v_name, title, link, + edition, duration, + public_time, cover_pic, sort, + u_xid, u_id, u_pic, u_name, + status, createtime, updatetime + ) VALUES ( + %(v_id)s, %(v_xid)s, %(rn)s, %(v_name)s, %(title)s, %(link)s, + '', %(duration)s, + %(create_time)s, %(cover_pic)s, %(sort)s, + %(u_xid)s, %(u_id)s, %(u_pic)s, %(u_name)s, + 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP() + ) + ON DUPLICATE KEY UPDATE + title = VALUES(title), + duration = VALUES(duration), + cover_pic = VALUES(cover_pic), + sort = VALUES(sort), + updatetime = UNIX_TIMESTAMP(); + """ - # 3) 删除旧表行 - sql_del = """ - DELETE FROM sh_dm_video_v2 - WHERE rn = %(rn)s - AND v_xid = %(v_xid)s - """ - self.cursor.execute(sql_del, data) - - # 4) 插入新表 - sql_ins = """ - INSERT INTO sh_dm_video_v2 ( - v_id, v_xid, rn, v_name, title, link, - is_piracy, edition, duration, - watch_number, follow_number, video_number, - public_time, cover_pic, sort, - u_xid, u_id, u_pic, u_name, - status, createtime, updatetime, - is_repeat - ) VALUES ( - %(v_id)s, %(v_xid)s, %(rn)s, %(v_name)s, %(title)s, %(link)s, - %(is_piracy)s, '', %(duration)s, - %(watch_number)s, %(fans)s, %(videos)s, - %(create_time)s, %(cover_pic)s, %(sort)s, - %(u_xid)s, %(u_id)s, %(u_pic)s, %(u_name)s, - 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), - %(is_repeat)s - ) - """ - self.cursor.execute(sql_ins, data) + self.cursor.execute(sql_update, data) break # 成功跳出重试循环 except Exception as e: