2023-10-30 06:31:15 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2023-10-30 07:52:39 +00:00
|
|
|
from pathlib import Path
|
|
|
|
|
2023-10-30 06:31:15 +00:00
|
|
|
from httpx import AsyncClient
|
|
|
|
from msgspec import convert
|
|
|
|
|
|
|
|
from starrail_damage_cal.mihomo.models import MihomoData
|
|
|
|
|
|
|
|
_HEADER = {"User-Agent": "StarRailDamageCal/"}
|
|
|
|
|
|
|
|
|
2023-10-30 07:52:39 +00:00
|
|
|
async def get_char_card_info(
|
|
|
|
uid: str,
|
|
|
|
save_path: Path | None = None,
|
|
|
|
) -> MihomoData:
|
2023-10-30 06:31:15 +00:00
|
|
|
async with AsyncClient(
|
|
|
|
base_url="http://api.mihomo.me",
|
|
|
|
headers=_HEADER,
|
|
|
|
timeout=30,
|
|
|
|
) as client:
|
|
|
|
req = await client.get(f"/sr_info/{uid}")
|
2023-10-30 07:52:39 +00:00
|
|
|
if save_path:
|
|
|
|
save_path.mkdir(parents=True, exist_ok=True)
|
|
|
|
with Path.open(save_path / uid / f"{uid!s}.json", "w") as file:
|
|
|
|
file.write(req.text)
|
2023-10-30 06:31:15 +00:00
|
|
|
return convert(req.json(), type=MihomoData)
|