️ 加速预绘制 (#8)

This commit is contained in:
lulu666lulu 2023-11-09 09:50:25 +08:00 committed by GitHub
parent 5763eec714
commit cb88f6e0ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 10 deletions

View File

@ -25,12 +25,17 @@ Spots = Dict[int, List[Spot]]
async def _request(
endpoint: str, client: AsyncClient = API_CLIENT
) -> Dict[str, Any]:
resp = await client.get(endpoint)
resp.raise_for_status()
data: Dict[str, Any] = resp.json()
if data["retcode"] != 0:
raise StatusError(data["retcode"], data["message"])
return data["data"]
while True:
try:
resp = await client.get(endpoint)
resp.raise_for_status()
data: Dict[str, Any] = resp.json()
if data["retcode"] != 0:
raise StatusError(data["retcode"], data["message"])
return data["data"]
except Exception as e:
if "Timeout" in str(e):
continue
async def get_labels(map_id: MapID) -> List[Tree]:

View File

@ -78,9 +78,16 @@ async def create_genshin_map():
map_img.save(MAP / f"{map_id.name}.png")
logger.info("****************** 开始绘制 *****************")
trees = await request.get_labels(map_id)
# for tree in trees:
# for label in tree.children:
# await get_map_response("PRE-START", label.name, map_id, False)
#改成并发
import asyncio
tasks = []
for tree in trees:
for label in tree.children:
await get_map_response("PRE-START", label.name, map_id, False)
tasks.append(get_map_response("PRE-START", label.name, map_id, False))
await asyncio.gather(*tasks)
logger.info("****************** 开始地图API服务 *****************")
@ -187,9 +194,16 @@ async def get_map_response(
)
icon_path = ICON_PATH / f"{resource_name}.png"
if not icon_path.exists():
await download_file(icon, icon_path)
icon_pic = Image.open(icon_path).resize((52, 52))
while True:
try:
if not icon_path.exists():
await download_file(icon, icon_path)
icon_pic = Image.open(icon_path).resize((52, 52))
except:
await download_file(icon, icon_path)
continue
break
if point.s == 1:
z = 1