From 65689e3df5f71064d3d3073c7bba42dc793d2081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A7=89?= Date: Thu, 16 Nov 2023 07:31:19 +0800 Subject: [PATCH] Refactor download_image function and add print statement for image OCR results --- main.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 1003864..db4ed23 100644 --- a/main.py +++ b/main.py @@ -11,7 +11,7 @@ config = dotenv_values(".env") ImageFile.LOAD_TRUNCATED_IMAGES = True # 下载图片(使用OSS下载) -def download_image(url:str) -> Image: +def download_image(url:str) -> Image.Image: if url.startswith('http://image.gameuiux.cn/') or url.startswith('https://image.gameuiux.cn/'): try: url = url.replace('http://image.gameuiux.cn/', '').replace('https://image.gameuiux.cn/', '') @@ -42,7 +42,6 @@ cursor.execute("SELECT id, content FROM web_images LIMIT 5") # 获取查询结果 rows = cursor.fetchall() for row in rows: - #print(row) image = download_image(row['content']) if image is None: print('图片下载失败,跳过') @@ -50,7 +49,7 @@ for row in rows: out = ocr.ocr(image) # 这段代码将只包含那些非空、不是纯数字且长度大于1的'text'值 texts = [item['text'] for item in out if item['text'] and not item['text'].isdigit() and len(item['text']) > 1] - print(texts) + print(row['id'], texts) # 关闭游标和连接