🐛 修复下载图标报错

This commit is contained in:
CMHopeSunshine 2022-12-08 11:42:00 +08:00
parent 10c98e6ba4
commit 1b625dcdef
3 changed files with 9 additions and 7 deletions

View File

@ -27,7 +27,7 @@ talent_color = [('#d5f2b6', '#6d993d'), ('#d5f2b6', '#6d993d'), ('#d5f2b6', '#6d
async def draw_chara_card(info: Character):
img = await aiorequests.get_img(f'http://img.genshin.cherishmoon.fun/{info.name}', mode='RGBA')
img = await aiorequests.get_img(f'http://img.genshin.cherishmoon.fun/{info.name}', mode='RGBA', follow_redirects=True)
if img == 'No Such File':
return '暂时没有这个角色的同人图哦~', None
# 新建卡片

View File

@ -96,7 +96,6 @@ class aiorequests:
headers=headers,
params=params,
timeout=timeout,
follow_redirects=True,
**kwargs)
# 不保存安柏计划的问号图标
if resp.headers.get('etag') == 'W/"6363798a-13c7"' or resp.headers.get(
@ -112,7 +111,6 @@ class aiorequests:
headers=headers,
params=params,
timeout=timeout,
follow_redirects=True,
**kwargs)
if resp.headers.get('etag') == 'W/"6363798a-13c7"' or resp.headers.get(
'content-md5') == 'JeG5b/z8SpViMmO/E9eayA==':

View File

@ -58,6 +58,7 @@ def cache(ttl=datetime.timedelta(hours=1)):
缓存装饰器
:param ttl: 过期时间
"""
def wrap(func):
cache_data = {}
@ -87,7 +88,9 @@ def cache(ttl=datetime.timedelta(hours=1)):
async def check_resource():
logger.info('资源检查', '开始检查资源')
try:
resource_list = await aiorequests.get(f'{config.github_proxy}https://raw.githubusercontent.com/CMHopeSunshine/LittlePaimonRes/main/resources_list.json')
resource_list = await aiorequests.get(
f'{config.github_proxy}https://raw.githubusercontent.com/CMHopeSunshine/LittlePaimonRes/main/resources_list.json',
follow_redirects=True)
resource_list = resource_list.json()
except Exception:
logger.info('资源检查', '读取资源列表<r>失败</r>,请尝试更换<m>github资源地址</m>')
@ -102,12 +105,13 @@ async def check_resource():
file_path.unlink()
flag = True
try:
await aiorequests.download(url=f'{config.github_proxy}https://raw.githubusercontent.com/CMHopeSunshine/LittlePaimonRes/main/{resource["path"]}',
save_path=file_path, exclude_json=resource['path'].split('.')[-1] != 'json')
await aiorequests.download(
url=f'{config.github_proxy}https://raw.githubusercontent.com/CMHopeSunshine/LittlePaimonRes/main/{resource["path"]}',
save_path=file_path, exclude_json=resource['path'].split('.')[-1] != 'json')
await asyncio.sleep(0.5)
except Exception:
logger.warning('资源检查', f'下载<m>{resource["path"]}</m>时<r>出错</r>,请尝试更换<m>github资源地址</m>')
if flag:
logger.info('资源检查', '<g>资源下载完成</g>')
else:
logger.info('资源检查', '<g>资源完好,无需下载</g>')
logger.info('资源检查', '<g>资源完好,无需下载</g>')