mirror of
https://github.com/PaiGramTeam/StarRailDamageCal.git
synced 2024-11-30 18:59:26 +00:00
add
This commit is contained in:
parent
a076e4a0e4
commit
6609a49328
@ -1,5 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from httpx import AsyncClient
|
from httpx import AsyncClient
|
||||||
from msgspec import convert
|
from msgspec import convert
|
||||||
|
|
||||||
@ -8,11 +10,18 @@ from starrail_damage_cal.mihomo.models import MihomoData
|
|||||||
_HEADER = {"User-Agent": "StarRailDamageCal/"}
|
_HEADER = {"User-Agent": "StarRailDamageCal/"}
|
||||||
|
|
||||||
|
|
||||||
async def get_char_card_info(uid: str) -> MihomoData:
|
async def get_char_card_info(
|
||||||
|
uid: str,
|
||||||
|
save_path: Path | None = None,
|
||||||
|
) -> MihomoData:
|
||||||
async with AsyncClient(
|
async with AsyncClient(
|
||||||
base_url="http://api.mihomo.me",
|
base_url="http://api.mihomo.me",
|
||||||
headers=_HEADER,
|
headers=_HEADER,
|
||||||
timeout=30,
|
timeout=30,
|
||||||
) as client:
|
) as client:
|
||||||
req = await client.get(f"/sr_info/{uid}")
|
req = await client.get(f"/sr_info/{uid}")
|
||||||
|
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)
|
||||||
return convert(req.json(), type=MihomoData)
|
return convert(req.json(), type=MihomoData)
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
from typing import Any, Dict, List, Tuple, Union
|
from typing import Any, Dict, List, Tuple, Union
|
||||||
|
|
||||||
|
from msgspec import json as msgjson
|
||||||
|
|
||||||
from starrail_damage_cal.damage.utils import cal_relic_main_affix, cal_relic_sub_affix
|
from starrail_damage_cal.damage.utils import cal_relic_main_affix, cal_relic_sub_affix
|
||||||
from starrail_damage_cal.excel.model import (
|
from starrail_damage_cal.excel.model import (
|
||||||
AvatarPromotionConfig,
|
AvatarPromotionConfig,
|
||||||
@ -34,6 +38,7 @@ from starrail_damage_cal.mihomo.requests import get_char_card_info
|
|||||||
async def api_to_dict(
|
async def api_to_dict(
|
||||||
sr_uid: Union[str, None] = None,
|
sr_uid: Union[str, None] = None,
|
||||||
mihomo_raw: Union[MihomoData, None] = None,
|
mihomo_raw: Union[MihomoData, None] = None,
|
||||||
|
save_path: Union[Path, None] = None,
|
||||||
) -> Tuple[List[str], Dict[str, Dict[str, Any]]]:
|
) -> Tuple[List[str], Dict[str, Dict[str, Any]]]:
|
||||||
if not mihomo_raw:
|
if not mihomo_raw:
|
||||||
if not sr_uid:
|
if not sr_uid:
|
||||||
@ -46,6 +51,15 @@ async def api_to_dict(
|
|||||||
sr_data = mihomo_raw
|
sr_data = mihomo_raw
|
||||||
|
|
||||||
PlayerDetailInfo = sr_data.detailInfo
|
PlayerDetailInfo = sr_data.detailInfo
|
||||||
|
|
||||||
|
if save_path:
|
||||||
|
path = save_path / str(sr_uid)
|
||||||
|
path.mkdir(parents=True, exist_ok=True)
|
||||||
|
with Path.open(path / f"{sr_uid!s}.json", "wb") as file:
|
||||||
|
file.write(msgjson.format(msgjson.encode(PlayerDetailInfo), indent=4))
|
||||||
|
with Path.open(path / "rawData.json", "wb") as file:
|
||||||
|
file.write(msgjson.format(msgjson.encode(sr_data), indent=4))
|
||||||
|
|
||||||
uid = str(PlayerDetailInfo.uid)
|
uid = str(PlayerDetailInfo.uid)
|
||||||
|
|
||||||
if sr_data.detailInfo is None:
|
if sr_data.detailInfo is None:
|
||||||
@ -85,7 +99,9 @@ async def api_to_dict(
|
|||||||
return (char_id_list, char_data_list)
|
return (char_id_list, char_data_list)
|
||||||
|
|
||||||
|
|
||||||
async def get_data(char: Avatar, nick_name: str, sr_uid: str):
|
async def get_data(
|
||||||
|
char: Avatar, nick_name: str, sr_uid: str, save_path: Union[Path, None] = None
|
||||||
|
):
|
||||||
# 处理基本信息
|
# 处理基本信息
|
||||||
char_data = {
|
char_data = {
|
||||||
"uid": str(sr_uid),
|
"uid": str(sr_uid),
|
||||||
@ -282,4 +298,9 @@ async def get_data(char: Avatar, nick_name: str, sr_uid: str):
|
|||||||
|
|
||||||
char_data["equipmentInfo"] = equipment_info
|
char_data["equipmentInfo"] = equipment_info
|
||||||
|
|
||||||
|
if save_path:
|
||||||
|
save_path.mkdir(parents=True, exist_ok=True)
|
||||||
|
with Path.open(save_path / f"{avatarName}.json", "w", encoding="UTF-8") as file:
|
||||||
|
json.dump(char_data, file, ensure_ascii=False)
|
||||||
|
|
||||||
return char_data, avatarName
|
return char_data, avatarName
|
||||||
|
Loading…
Reference in New Issue
Block a user