Add starrail hoyolab diary

This commit is contained in:
omg-xtao 2023-06-23 22:54:42 +08:00 committed by GitHub
parent 15c7228e2c
commit 5962573495
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 14 deletions

View File

@ -1,5 +1,5 @@
from datetime import timedelta, timezone, datetime from datetime import timedelta, timezone, datetime
from typing import Optional, Any, Dict from typing import Optional, Any, Dict, Union
from simnet.client.base import BaseClient from simnet.client.base import BaseClient
from simnet.client.routes import DETAIL_LEDGER_URL, INFO_LEDGER_URL from simnet.client.routes import DETAIL_LEDGER_URL, INFO_LEDGER_URL
@ -22,7 +22,7 @@ class BaseDiaryClient(BaseClient):
*, *,
game: Optional[Game] = None, game: Optional[Game] = None,
detail: bool = False, detail: bool = False,
month: Optional[int] = None, month: Union[int, str, None] = None,
lang: Optional[str] = None, lang: Optional[str] = None,
params: Optional[Dict[str, Any]] = None, params: Optional[Dict[str, Any]] = None,
) -> Dict[str, Any]: ) -> Dict[str, Any]:
@ -43,14 +43,8 @@ class BaseDiaryClient(BaseClient):
player_id = player_id or self.player_id player_id = player_id or self.player_id
params = params or {} params = params or {}
url = ( base_url = DETAIL_LEDGER_URL if detail else INFO_LEDGER_URL
DETAIL_LEDGER_URL.get_url(self.region, game) url = base_url.get_url(self.region, game)
if detail
else INFO_LEDGER_URL.get_url(
self.region,
game,
)
)
if self.region == Region.OVERSEAS or game == Game.STARRAIL: if self.region == Region.OVERSEAS or game == Game.STARRAIL:
params["uid"] = player_id params["uid"] = player_id
@ -60,7 +54,11 @@ class BaseDiaryClient(BaseClient):
params["bind_region"] = recognize_server(player_id, game) params["bind_region"] = recognize_server(player_id, game)
else: else:
raise TypeError(f"{self.region!r} is not a valid region.") raise TypeError(f"{self.region!r} is not a valid region.")
params["month"] = month or (datetime.now().strftime("%Y%m") if game == Game.STARRAIL else datetime.now().month) if game == Game.STARRAIL:
month = month or datetime.now(CN_TIMEZONE).strftime("%Y%m")
elif game == Game.GENSHIN:
month = month or str(datetime.now(CN_TIMEZONE).month)
params["month"] = month
params["lang"] = lang or self.lang params["lang"] = lang or self.lang
return await self.request_lab(url, params=params) return await self.request_lab(url, params=params)

View File

@ -12,7 +12,7 @@ class StarrailDiaryClient(BaseDiaryClient):
self, self,
player_id: Optional[int] = None, player_id: Optional[int] = None,
*, *,
month: Optional[int] = None, month: Optional[str] = None,
lang: Optional[str] = None, lang: Optional[str] = None,
) -> StarRailDiary: ) -> StarRailDiary:
"""Get a traveler's diary with earning details for the month. """Get a traveler's diary with earning details for the month.

View File

@ -253,7 +253,7 @@ CALCULATOR_URL = InternationalRoute(
DETAIL_LEDGER_URL = GameRoute( DETAIL_LEDGER_URL = GameRoute(
overseas=dict( overseas=dict(
genshin="https://sg-hk4e-api.hoyolab.com/event/ysledgeros/month_detail", genshin="https://sg-hk4e-api.hoyolab.com/event/ysledgeros/month_detail",
hkrpg="", hkrpg="https://sg-public-api.hoyolab.com/event/srledger/month_detail",
), ),
chinese=dict( chinese=dict(
genshin="https://hk4e-api.mihoyo.com/event/ys_ledger/monthDetail", genshin="https://hk4e-api.mihoyo.com/event/ys_ledger/monthDetail",
@ -264,7 +264,7 @@ DETAIL_LEDGER_URL = GameRoute(
INFO_LEDGER_URL = GameRoute( INFO_LEDGER_URL = GameRoute(
overseas=dict( overseas=dict(
genshin="https://sg-hk4e-api.hoyolab.com/event/ysledgeros/month_info", genshin="https://sg-hk4e-api.hoyolab.com/event/ysledgeros/month_info",
hkrpg="", hkrpg="https://sg-public-api.hoyolab.com/event/srledger/month_info",
), ),
chinese=dict( chinese=dict(
genshin="https://hk4e-api.mihoyo.com/event/ys_ledger/monthInfo", genshin="https://hk4e-api.mihoyo.com/event/ys_ledger/monthInfo",