init
This commit is contained in:
55
main.py
Normal file
55
main.py
Normal file
@@ -0,0 +1,55 @@
|
||||
import io
|
||||
import oss2
|
||||
import requests
|
||||
|
||||
from PIL import Image, ImageFile
|
||||
|
||||
ImageFile.LOAD_TRUNCATED_IMAGES = True
|
||||
|
||||
# 下载图片(使用OSS下载)
|
||||
def download_image(url:str) -> 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/', '')
|
||||
oss2.defaults.connection_pool_size = 100
|
||||
oss_host = 'oss-cn-shanghai-internal.aliyuncs.com'
|
||||
oss_auth = oss2.Auth('LTAI4GH3qP6VA3QpmTYCgXEW', 'r2wz4bJty8iYfGIcFmEqlY1yon2Ruy')
|
||||
return Image.open(io.BytesIO(oss2.Bucket(oss_auth, f'http://{oss_host}', 'gameui-image2').get_object(url).read()))
|
||||
except Exception:
|
||||
return None
|
||||
else:
|
||||
try:
|
||||
response = requests.get(url)
|
||||
return Image.open(io.BytesIO(response.content))
|
||||
except Exception:
|
||||
print('图片下载失败:', url)
|
||||
return None
|
||||
|
||||
|
||||
import pymysql
|
||||
import pymysql.cursors
|
||||
|
||||
conn = pymysql.connect(host='172.21.216.35', user='gameui', password='gameui@2022', database='gameui', cursorclass=pymysql.cursors.DictCursor)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT id, content FROM web_images LIMIT 10")
|
||||
|
||||
# 获取查询结果
|
||||
rows = cursor.fetchall()
|
||||
for row in rows:
|
||||
print(row)
|
||||
image = download_image(row.content)
|
||||
|
||||
# 关闭游标和连接
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
|
||||
'''
|
||||
from cnocr import CnOcr
|
||||
|
||||
img_fp = './x.jpg'
|
||||
ocr = CnOcr(rec_model_name='ch_PP-OCRv3') # 所有参数都使用默认值
|
||||
out = ocr.ocr(img_fp)
|
||||
|
||||
print(out)
|
||||
'''
|
Reference in New Issue
Block a user