Update data_source.py

This commit is contained in:
HibiKier 2021-06-17 10:21:32 +08:00 committed by GitHub
parent 98fb742d4d
commit 5eb0319ce5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,7 +17,6 @@ except ModuleNotFoundError:
async def update_setu_img():
try:
async with aiohttp.ClientSession(headers=get_user_agent()) as session:
for file_name in ['setu_url.json', 'setu_r18_url.json']:
if file_name == 'setu_url.json':
@ -85,6 +84,7 @@ async def update_setu_img():
os.rename(IMAGE_PATH + rar_path + index + ".jpg",
IMAGE_PATH + path + index + ".jpg")
except FileNotFoundError:
logger.warning(f'文件 {index}.jpg 不存在,跳过...')
_success -= 1
continue
img_hash = str(get_img_hash(f'{IMAGE_PATH}{path}{index}.jpg'))
@ -106,6 +106,14 @@ async def update_setu_img():
except (TimeoutError, ClientConnectorError) as e:
logger.warning(f'{url} 更新失败 ..{type(e)}{e}')
continue
except Exception as e:
await get_bot().send_private_msg(
user_id=int(list(get_bot().config.superusers)[0]),
message=f'更新 {index}.jpg 色图错误 {type(e)}: {e}'
)
_success -= 1
logger.error(f'更新色图 {index}.jpg 错误 {type(e)}: {e}')
continue
with open(TXT_PATH + json_name, 'w', encoding='utf-8') as f:
json.dump(data, f, indent=4, ensure_ascii=False)
open(TXT_PATH + file_name, 'w')
@ -117,9 +125,3 @@ async def update_setu_img():
message=f'{str(datetime.now()).split(".")[0]} 更新{file_name.split(".")[0]}完成,预计更新 {total} 张,'
f'实际更新 {_success} 张,相似 {_similar} 张,实际存入 {_success - _similar}'
)
except Exception as e:
await get_bot().send_private_msg(
user_id=int(list(get_bot().config.superusers)[0]),
message=f'更新色图错误 {type(e)}: {e}'
)
logger.error(f'更新色图错误 {type(e)}: {e}')