mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
Update data_source.py
This commit is contained in:
parent
98fb742d4d
commit
5eb0319ce5
@ -17,7 +17,6 @@ except ModuleNotFoundError:
|
|||||||
|
|
||||||
|
|
||||||
async def update_setu_img():
|
async def update_setu_img():
|
||||||
try:
|
|
||||||
async with aiohttp.ClientSession(headers=get_user_agent()) as session:
|
async with aiohttp.ClientSession(headers=get_user_agent()) as session:
|
||||||
for file_name in ['setu_url.json', 'setu_r18_url.json']:
|
for file_name in ['setu_url.json', 'setu_r18_url.json']:
|
||||||
if file_name == 'setu_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",
|
os.rename(IMAGE_PATH + rar_path + index + ".jpg",
|
||||||
IMAGE_PATH + path + index + ".jpg")
|
IMAGE_PATH + path + index + ".jpg")
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
|
logger.warning(f'文件 {index}.jpg 不存在,跳过...')
|
||||||
_success -= 1
|
_success -= 1
|
||||||
continue
|
continue
|
||||||
img_hash = str(get_img_hash(f'{IMAGE_PATH}{path}{index}.jpg'))
|
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:
|
except (TimeoutError, ClientConnectorError) as e:
|
||||||
logger.warning(f'{url} 更新失败 ..{type(e)}:{e}')
|
logger.warning(f'{url} 更新失败 ..{type(e)}:{e}')
|
||||||
continue
|
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:
|
with open(TXT_PATH + json_name, 'w', encoding='utf-8') as f:
|
||||||
json.dump(data, f, indent=4, ensure_ascii=False)
|
json.dump(data, f, indent=4, ensure_ascii=False)
|
||||||
open(TXT_PATH + file_name, 'w')
|
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} 张,'
|
message=f'{str(datetime.now()).split(".")[0]} 更新{file_name.split(".")[0]}完成,预计更新 {total} 张,'
|
||||||
f'实际更新 {_success} 张,相似 {_similar} 张,实际存入 {_success - _similar} 张'
|
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}')
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user