🎨 chore: support retry

This commit is contained in:
xtaodada 2023-07-18 23:53:05 +08:00
parent 69cab2f6aa
commit 723e4a1e9a
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659

View File

@ -35,13 +35,27 @@ async def get_single_avatar(url: str) -> None:
avatar_data[str(avatar.id)] = urls
def retry(func):
async def wrapper(*args, **kwargs):
for i in range(3):
try:
await func(*args, **kwargs)
break
except Exception:
print(f"重试 {func.__name__} {i + 1}")
await asyncio.sleep(1)
return wrapper
@retry
async def get_single_avatar_skill_icon(url: str, real_path: str) -> None:
req = await client.get(url)
try:
req.raise_for_status()
except Exception:
except Exception as e:
print(f"{url} 获取技能图片失败")
return
raise e
async with aiofiles.open(f"data/skill/{real_path}", "wb") as f:
await f.write(req.content)
if "8001" in real_path: