Skip to content

Commit

Permalink
Handle special card wapi endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
seriaati committed Jul 8, 2024
1 parent 544b9f0 commit c249d3d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 11 additions & 3 deletions genshin/client/components/chronicle/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,20 @@ async def request_game_record(
*,
lang: typing.Optional[str] = None,
region: typing.Optional[types.Region] = None,
game: typing.Optional[types.Game] = None,
is_card_wapi: bool = False,
**kwargs: typing.Any,
) -> typing.Mapping[str, typing.Any]:
"""Make a request towards the game record endpoint."""
game = game or self.default_game
if game is None:
raise RuntimeError("No default game set.")

base_url = routes.RECORD_URL.get_url(region or self.region, game)
base_url = (
routes.RECORD_URL.get_url(region or self.region, game)
if not is_card_wapi
else routes.CARD_WAPI_URL.get_url(region or self.region)
)
url = base_url / endpoint

mi18n_task = asyncio.create_task(self._fetch_mi18n("bbs", lang=lang or self.lang))
Expand Down Expand Up @@ -78,9 +84,10 @@ async def get_record_cards(
cache_key = cache.cache_key("records", hoyolab_id=hoyolab_id, lang=lang or self.lang)
if not (data := await self.cache.get(cache_key)):
data = await self.request_game_record(
"card/wapi/getGameRecordCard",
"getGameRecordCard",
lang=lang,
params=dict(uid=hoyolab_id),
is_card_wapi=True,
)

if data["list"]:
Expand Down Expand Up @@ -128,9 +135,10 @@ async def update_settings(
game_id = {types.Game.HONKAI: 1, types.Game.GENSHIN: 2, types.Game.STARRAIL: 6, types.Game.ZZZ: 8}[game]

await self.request_game_record(
"card/wapi/changeDataSwitch",
"changeDataSwitch",
method="POST",
data=dict(switch_id=int(setting), is_public=on, game_id=game_id),
is_card_wapi=True,
)

@deprecation.deprecated("update_settings")
Expand Down
5 changes: 5 additions & 0 deletions genshin/client/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"BBS_REFERER_URL",
"BBS_URL",
"CALCULATOR_URL",
"CARD_WAPI_URL",
"CHECK_QRCODE_URL",
"CN_WEB_LOGIN_URL",
"COMMUNITY_URL",
Expand Down Expand Up @@ -148,6 +149,10 @@ def get_url(self, region: types.Region, game: types.Game) -> yarl.URL:
nap="https://api-takumi-record.mihoyo.com/event/game_record_zzz/api/zzz",
),
)
CARD_WAPI_URL = InternationalRoute(
overseas="https://bbs-api-os.hoyolab.com/game_record/card/wapi",
chinese="https://api-takumi-record.mihoyo.com/game_record/app/card/wapi",
)
LINEUP_URL = InternationalRoute(
overseas="https://sg-public-api.hoyoverse.com/event/simulatoros/",
chinese="https://api-takumi.mihoyo.com/event/platsimulator/",
Expand Down

0 comments on commit c249d3d

Please sign in to comment.