From 4465f1f9f0a45d61419ba0bc195105b64028e58f Mon Sep 17 00:00:00 2001 From: satori Date: Tue, 19 Nov 2024 15:27:40 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B0=A1=E5=8C=96=E8=B7=B3=E8=A1=8C=E9=82=8F?= =?UTF-8?q?=E8=BC=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pp.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pp.py b/pp.py index fad84c3..eb1d72f 100755 --- a/pp.py +++ b/pp.py @@ -81,10 +81,7 @@ JP = PaddleOCR(use_angle_cls=True, lang="japan") KR = PaddleOCR(use_angle_cls=True, lang="korean") RU = PaddleOCR(use_angle_cls=True, lang="ru") -offset=1500 - -def process_images(conn): - global offset +def process_images(conn, offset=0) -> int: with conn.cursor(pymysql.cursors.SSCursor) as cursor: cursor.execute("SELECT id, content FROM web_images WHERE text='' AND article_category_top_id=22 LIMIT 100 OFFSET %s", (offset,)) for id, content in cursor.fetchall(): @@ -142,12 +139,13 @@ def process_images(conn): data = json.dumps(data, ensure_ascii=False, cls=MyEncoder) cursor.execute("UPDATE web_images SET text = %s WHERE id = %s", (data, id)) conn.commit() - offset+=100 + return offset+100 def main(): conn = connect_to_mysql() + offset = 1500 while True: - process_images(conn) + offset = process_images(conn, offset) time.sleep(0)