Skip to content

Commit

Permalink
🧑‍💻 新增一部分安柏计划API (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
KimigaiiWuyi committed Apr 23, 2023
1 parent 4f21d66 commit 12e3e52
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 17 deletions.
1 change: 0 additions & 1 deletion GenshinUID/genshinuid_mysbbscoin/get_mihoyo_bbs_coin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import Dict, Literal

from httpx import AsyncClient

from gsuid_core.logger import logger

from ..utils.mys_api import mys_api
Expand Down
4 changes: 4 additions & 0 deletions GenshinUID/gsuid_utils/api/ambr/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
AMBR_BOOK_URL = 'https://api.ambr.top/v2/chs/book?vh=34F5'
AMBR_BOOK_DETAILS_URL = 'https://api.ambr.top/v2/CHS/book/{}?vh=34F5'
AMBR_BOOK_DATA_URL = 'https://api.ambr.top/v2/CHS/readable/Book{}?vh=34F5'
AMBR_MONSTER_URL = 'https://api.ambr.top/v2/chs/monster/{}?vh=37F4'
AMBR_GCG_LIST_URL = 'https://api.ambr.top/v2/chs/gcg?vh=37F4'
AMBR_GCG_DETAIL = 'https://api.ambr.top/v2/chs/gcg/{}?vh=37F4'
AMBR_MONSTER_LIST = 'https://api.ambr.top/v2/chs/monster?vh=37F4'
103 changes: 102 additions & 1 deletion GenshinUID/gsuid_utils/api/ambr/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Dict, List, Literal, Optional, TypedDict
from typing import Dict, List, Union, Literal, Optional, TypedDict, NotRequired


class AmbrLanguageData(TypedDict):
Expand Down Expand Up @@ -163,3 +163,104 @@ class AmbrBookDetail(TypedDict):
icon: str
volume: List[AmbrVolume]
route: str


class AmbrMonsterAffix(TypedDict):
name: str
description: str
abilityName: List[str]
isCommon: bool


class AmbrHpDrop(TypedDict):
id: int
hpPercent: int


class AmbrReward(TypedDict):
rank: int
icon: str
count: NotRequired[str]


class AmbrEntry(TypedDict):
id: str
type: str
affix: List[AmbrMonsterAffix]
hpDrops: List[AmbrHpDrop]
prop: List[AmbrProp]
resistance: Dict[str, float]
reward: Dict[str, AmbrReward]


class AmbrMonster(TypedDict):
id: int
name: str
icon: str
route: str
title: str
specialName: str
description: str
entries: Dict[str, AmbrEntry]
tips: Optional[str]


class AmbrMonsterSimple(TypedDict):
id: int
name: str
icon: str
route: str
type: str


class AmbrGCGList(TypedDict):
types: Dict[str, Literal['characterCard', 'actionCard']]
items: Dict[str, AmbrGCGCard]


class AmbrGCGCard(TypedDict):
id: int
name: str
type: Literal['characterCard', 'actionCard']
tags: Dict[str, str]
props: Dict[str, int]
icon: str
route: str
sortOrder: int


class AmbrGCGDict(TypedDict):
name: str
description: str


class AmbrGCGTalent(TypedDict):
name: str
description: str
cost: Dict[str, int]
params: Dict[str, Union[int, str]]
tags: Dict[str, str]
icon: str
subSkills: Optional[str]
keywords: Dict[str, str]


class AmbrGCGEntry(TypedDict):
id: int
name: str
type: Literal['gcg']
icon: str


class AmbrGCGDetail(AmbrGCGCard):
storyTitle: str
storyDetail: str
source: str
dictionary: Dict[str, AmbrGCGDict]
talent: Dict[str, AmbrGCGTalent]
relatedEntries: List[AmbrGCGCard]


class AmbrMonsterList(TypedDict):
types: Dict[str, str]
items: Dict[str, AmbrMonsterSimple]
40 changes: 40 additions & 0 deletions GenshinUID/gsuid_utils/api/ambr/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,22 @@
AmbrBook,
AmbrEvent,
AmbrWeapon,
AmbrGCGList,
AmbrMonster,
AmbrCharacter,
AmbrGCGDetail,
AmbrBookDetail,
AmbrMonsterList,
)
from .api import (
AMBR_BOOK_URL,
AMBR_CHAR_URL,
AMBR_EVENT_URL,
AMBR_GCG_DETAIL,
AMBR_WEAPON_URL,
AMBR_MONSTER_URL,
AMBR_GCG_LIST_URL,
AMBR_MONSTER_LIST,
AMBR_BOOK_DATA_URL,
AMBR_BOOK_DETAILS_URL,
)
Expand All @@ -43,6 +51,38 @@ async def get_ambr_char_data(id: Union[int, str]) -> Optional[AmbrCharacter]:
return None


async def get_ambr_monster_data(id: Union[int, str]) -> Optional[AmbrMonster]:
data = await _ambr_request(url=AMBR_MONSTER_URL.format(id))
if isinstance(data, Dict) and data['response'] == 200:
data = data['data']
return cast(AmbrMonster, data)
return None


async def get_ambr_gcg_detail(id: Union[int, str]) -> Optional[AmbrGCGDetail]:
data = await _ambr_request(url=AMBR_GCG_DETAIL.format(id))
if isinstance(data, Dict) and data['response'] == 200:
data = data['data']
return cast(AmbrGCGDetail, data)
return None


async def get_ambr_gcg_list() -> Optional[AmbrGCGList]:
data = await _ambr_request(url=AMBR_GCG_LIST_URL)
if isinstance(data, Dict) and data['response'] == 200:
data = data['data']
return cast(AmbrGCGList, data)
return None


async def get_ambr_monster_list() -> Optional[AmbrMonsterList]:
data = await _ambr_request(url=AMBR_MONSTER_LIST)
if isinstance(data, Dict) and data['response'] == 200:
data = data['data']
return cast(AmbrMonsterList, data)
return None


async def get_ambr_weapon_data(id: Union[int, str]) -> Optional[AmbrWeapon]:
data = await _ambr_request(url=AMBR_WEAPON_URL.format(id))
if isinstance(data, Dict) and data['response'] == 200:
Expand Down
44 changes: 29 additions & 15 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 12e3e52

Please sign in to comment.