From 1335f3fbed76ff69413f314a209aa3f3203e8028 Mon Sep 17 00:00:00 2001 From: qwerdvd <2450899274@qq.com> Date: Mon, 9 Oct 2023 16:04:27 +0800 Subject: [PATCH] add more hakush api --- StarRailUID/sruid_utils/api/hakush/model.py | 61 +++++++++++++++++- .../sruid_utils/api/hakush/requests.py | 64 +++++++++++++++++++ 2 files changed, 122 insertions(+), 3 deletions(-) create mode 100644 StarRailUID/sruid_utils/api/hakush/requests.py diff --git a/StarRailUID/sruid_utils/api/hakush/model.py b/StarRailUID/sruid_utils/api/hakush/model.py index 6fa4a25..4a243ca 100644 --- a/StarRailUID/sruid_utils/api/hakush/model.py +++ b/StarRailUID/sruid_utils/api/hakush/model.py @@ -41,7 +41,7 @@ class HakushHsrCharacterSkill(Struct): Level: Dict[str, HakushHsrCharacterSkillLevel] -class HakushHsrCharacterMaterial(Struct): +class HakushHsrMaterial(Struct): ItemID: int ItemNum: int @@ -56,7 +56,7 @@ class HakushHsrCharacterSkillTree(Struct): DefaultUnlock: bool Icon: str LevelUpSkillID: List[int] - MaterialList: List[Union[HakushHsrCharacterMaterial, None]] + MaterialList: List[Union[HakushHsrMaterial, None]] MaxLevel: int ParamList: List[float] PointID: int @@ -81,7 +81,7 @@ class HakushHsrCharacterStats(Struct): CriticalChance: float CriticalDamage: float BaseAggro: float - Cost: List[Union[HakushHsrCharacterMaterial, None]] + Cost: List[Union[HakushHsrMaterial, None]] class HakushHsrCharacterRelicProperty(Struct): @@ -110,3 +110,58 @@ class HakushHsrCharacter(Struct): SkillTrees: Dict[str, Dict[str, HakushHsrCharacterSkillTree]] Stats: Dict[str, HakushHsrCharacterStats] Relics: HakushHsrCharacterRelic + + +class LightconeRefinementLevel(Struct): + ParamList: List[float] + + +class HakushHsrLightconeRefinement(Struct): + Desc: str + Level: Dict[str, LightconeRefinementLevel] + Name: str + + +class HakushHsrLightconeStat(Struct): + BaseAttack: float + BaseAttackAdd: float + BaseDefence: float + BaseDefenceAdd: float + BaseHP: float + BaseHPAdd: float + EquipmentID: int + MaxLevel: int + PromotionCostList: List[HakushHsrMaterial] + PlayerLevelRequire: Union[int, None] = None + WorldLevelRequire: Union[int, None] = None + + +class HakushHsrLightcone(Struct): + Name: str + Desc: str + Rarity: str + BaseType: str + Refinements: HakushHsrLightconeRefinement + Stats: List[HakushHsrLightconeStat] + + +class HakushHsrCharacterIndex(Struct): + icon: str + rank: str + baseType: str + damageType: str + en: str + desc: str + kr: str + cn: str + jp: str + + +class HakushHsrLightconeIndex(Struct): + rank: str + baseType: str + en: str + desc: str + kr: str + cn: str + jp: str diff --git a/StarRailUID/sruid_utils/api/hakush/requests.py b/StarRailUID/sruid_utils/api/hakush/requests.py new file mode 100644 index 0000000..fee833e --- /dev/null +++ b/StarRailUID/sruid_utils/api/hakush/requests.py @@ -0,0 +1,64 @@ +from typing import Dict, Union + +from httpx import AsyncClient +from msgspec import convert + +from ..utils import _HEADER +from .model import ( + HakushHsrCharacter, + HakushHsrCharacterIndex, + HakushHsrLightcone, + HakushHsrLightconeIndex, +) + + +async def get_character_data(uid: str) -> Union[HakushHsrCharacter, None]: + async with AsyncClient( + base_url='https://api.hakush.in/hsr/data', + headers=_HEADER, + timeout=30, + ) as client: + req = await client.get(f'/cn/character/{uid}.json') + if req.status_code == 200: + return convert(req.json(), type=HakushHsrCharacter) + return None + + +async def get_lightcone_data(uid: str) -> Union[HakushHsrLightcone, None]: + async with AsyncClient( + base_url='https://api.hakush.in/hsr/data', + headers=_HEADER, + timeout=30, + ) as client: + req = await client.get(f'/cn/lightcone/{uid}.json') + if req.status_code == 200: + return convert(req.json(), type=HakushHsrLightcone) + return None + + +async def get_character_index() -> Union[ + Dict[str, HakushHsrCharacterIndex], None +]: + async with AsyncClient( + base_url='https://api.hakush.in/hsr/data', + headers=_HEADER, + timeout=30, + ) as client: + req = await client.get('/character.json') + if req.status_code == 200: + return convert(req.json(), type=Dict[str, HakushHsrCharacterIndex]) + return None + + +async def get_lightcone_index() -> Union[ + Dict[str, HakushHsrLightconeIndex], None +]: + async with AsyncClient( + base_url='https://api.hakush.in/hsr/data', + headers=_HEADER, + timeout=30, + ) as client: + req = await client.get('/character.json') + if req.status_code == 200: + return convert(req.json(), type=Dict[str, HakushHsrLightconeIndex]) + return None