mirror of
https://github.com/PaiGramTeam/fastapi_genshin_map.git
synced 2024-11-16 03:55:30 +00:00
⚡️ 加速预绘制 (#8)
This commit is contained in:
parent
5763eec714
commit
cb88f6e0ae
@ -25,12 +25,17 @@ Spots = Dict[int, List[Spot]]
|
||||
async def _request(
|
||||
endpoint: str, client: AsyncClient = API_CLIENT
|
||||
) -> Dict[str, Any]:
|
||||
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]:
|
||||
|
@ -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"
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user