簡化跳行邏輯
This commit is contained in:
10
pp.py
10
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)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user