Module genshin.client.components.diary
Diary component.
Classes
class DiaryClient (cookies: Union[ForwardRef('http.cookies.BaseCookie[Any]'), Mapping[Any, Any], str, Sequence[Union[ForwardRef('http.cookies.BaseCookie[Any]'), Mapping[Any, Any], str]], ForwardRef(None)] = None, *, authkey: Optional[str] = None, lang: str = 'en-us', region: Region = Region.OVERSEAS, proxy: Optional[str] = None, game: Optional[Game] = None, uid: Optional[int] = None, hoyolab_id: Optional[int] = None, device_id: Optional[str] = None, device_fp: Optional[str] = None, headers: Union[Mapping[str, str], Mapping[multidict._multidict.istr, str], multidict._multidict.CIMultiDict, multidict._multidict.CIMultiDictProxy, Iterable[Tuple[Union[str, multidict._multidict.istr], str]], ForwardRef(None)] = None, cache: Optional[BaseCache] = None, debug: bool = False)
-
Diary component.
Expand source code
class DiaryClient(base.BaseClient): """Diary component.""" @managers.no_multi async def request_ledger( self, uid: typing.Optional[int] = None, *, game: typing.Optional[types.Game] = None, detail: bool = False, month: typing.Union[int, str, None] = None, lang: typing.Optional[str] = None, params: typing.Optional[typing.Mapping[str, typing.Any]] = None, **kwargs: typing.Any, ) -> typing.Mapping[str, typing.Any]: """Make a request towards the ys ledger endpoint.""" # TODO: Do not separate urls? params = dict(params or {}) if game is None: if self.default_game is None: raise RuntimeError("No default game set.") game = self.default_game base_url = routes.DETAIL_LEDGER_URL if detail else routes.INFO_LEDGER_URL url = base_url.get_url(self.region, game) uid = uid or await self._get_uid(game) if self.region == types.Region.OVERSEAS or game == types.Game.STARRAIL: params["uid"] = uid params["region"] = utility.recognize_server(uid, game) elif self.region == types.Region.CHINESE: params["bind_uid"] = uid params["bind_region"] = utility.recognize_server(uid, game) else: raise TypeError(f"{self.region!r} is not a valid region.") params["month"] = month or ( datetime.datetime.now().strftime("%Y%m") if game == types.Game.STARRAIL else datetime.datetime.now().month ) params["lang"] = lang or self.lang return await self.request(url, params=params, **kwargs) @deprecation.deprecated("get_genshin_diary") async def get_diary( self, uid: typing.Optional[int] = None, *, month: typing.Optional[int] = None, lang: typing.Optional[str] = None, ) -> models.Diary: """Get a traveler's diary with earning details for the month.""" return await self.get_genshin_diary(uid, month=month, lang=lang) async def get_genshin_diary( self, uid: typing.Optional[int] = None, *, month: typing.Optional[int] = None, lang: typing.Optional[str] = None, ) -> models.Diary: """Get a traveler's diary with earning details for the month.""" game = types.Game.GENSHIN uid = uid or await self._get_uid(game) cache_key = cache.cache_key( "diary", uid=uid, game=game, month=month or datetime.datetime.now(CN_TIMEZONE).month, lang=lang or self.lang ) data = await self.request_ledger(uid, game=game, month=month, lang=lang, cache=cache_key) return models.Diary(**data) async def get_starrail_diary( self, uid: typing.Optional[int] = None, *, month: typing.Optional[int] = None, lang: typing.Optional[str] = None, ) -> models.StarRailDiary: """Get a blazer's diary with earning details for the month.""" game = types.Game.STARRAIL uid = uid or await self._get_uid(game) cache_key = cache.cache_key( "diary", uid=uid, game=game, month=month or datetime.datetime.now(CN_TIMEZONE).month, lang=lang or self.lang ) data = await self.request_ledger(uid, game=game, month=month, lang=lang, cache=cache_key) return models.StarRailDiary(**data) async def _get_genshin_diary_page( self, page: int, *, uid: typing.Optional[int] = None, type: int = models.DiaryType.PRIMOGEMS, month: typing.Optional[int] = None, lang: typing.Optional[str] = None, ) -> models.DiaryPage: data = await self.request_ledger( uid, game=types.Game.GENSHIN, detail=True, month=month, lang=lang, params=dict(type=type, current_page=page, page_size=100), ) return models.DiaryPage(**data) @deprecation.deprecated("genshin_diary_log") def diary_log( self, uid: typing.Optional[int] = None, *, limit: typing.Optional[int] = None, type: int = models.DiaryType.PRIMOGEMS, month: typing.Optional[int] = None, lang: typing.Optional[str] = None, ) -> DiaryPaginator: """Create a new daily reward paginator.""" return self.genshin_diary_log( uid=uid, limit=limit, type=type, month=month, lang=lang, ) def genshin_diary_log( self, uid: typing.Optional[int] = None, *, limit: typing.Optional[int] = None, type: int = models.DiaryType.PRIMOGEMS, month: typing.Optional[int] = None, lang: typing.Optional[str] = None, ) -> DiaryPaginator: """Create a new daily reward paginator.""" return DiaryPaginator( functools.partial( self._get_genshin_diary_page, uid=uid, type=type, month=month, lang=lang, ), limit=limit, ) async def _get_starrail_diary_page( self, page: int, *, uid: typing.Optional[int] = None, type: int = models.StarRailDiaryType.STELLARJADE, month: typing.Optional[str] = None, lang: typing.Optional[str] = None, ) -> models.StarRailDiaryPage: data = await self.request_ledger( uid, game=types.Game.STARRAIL, detail=True, month=month, lang=lang, params=dict(type=type, current_page=page, page_size=100), ) return models.StarRailDiaryPage(**data) def starrail_diary_log( self, uid: typing.Optional[int] = None, *, limit: typing.Optional[int] = None, type: int = models.StarRailDiaryType.STELLARJADE, month: typing.Optional[str] = None, lang: typing.Optional[str] = None, ) -> StarRailDiaryPaginator: """Create a new daily reward paginator.""" return StarRailDiaryPaginator( functools.partial( self._get_starrail_diary_page, uid=uid, type=type, month=month, lang=lang, ), limit=limit, )
Ancestors
- BaseClient
- abc.ABC
Subclasses
Class variables
var logger : logging.Logger
Instance variables
var authkeys : dict[Game, str]
var cache : BaseCache
var custom_headers : multidict._multidict.CIMultiDict[str]
var uids : dict[Game, int]
Methods
def diary_log(self, uid: Optional[int] = None, *, limit: Optional[int] = None, type: int = DiaryType.PRIMOGEMS, month: Optional[int] = None, lang: Optional[str] = None) ‑> genshin.client.components.diary.DiaryPaginator
-
Create a new daily reward paginator.
Warning
This function is deprecated and will be removed in the following version. You can use
genshin_diary_log
instead. def genshin_diary_log(self, uid: Optional[int] = None, *, limit: Optional[int] = None, type: int = DiaryType.PRIMOGEMS, month: Optional[int] = None, lang: Optional[str] = None) ‑> genshin.client.components.diary.DiaryPaginator
-
Create a new daily reward paginator.
async def get_diary(self, uid: Optional[int] = None, *, month: Optional[int] = None, lang: Optional[str] = None) ‑> Diary
-
Get a traveler's diary with earning details for the month.
Warning
This function is deprecated and will be removed in the following version. You can use
get_genshin_diary
instead. async def get_genshin_diary(self, uid: Optional[int] = None, *, month: Optional[int] = None, lang: Optional[str] = None) ‑> Diary
-
Get a traveler's diary with earning details for the month.
async def get_starrail_diary(self, uid: Optional[int] = None, *, month: Optional[int] = None, lang: Optional[str] = None) ‑> StarRailDiary
-
Get a blazer's diary with earning details for the month.
async def request_ledger(self, uid: Optional[int] = None, *, game: Optional[Game] = None, detail: bool = False, month: Union[int, str, ForwardRef(None)] = None, lang: Optional[str] = None, params: Optional[Mapping[str, Any]] = None, **kwargs: Any) ‑> Mapping[str, Any]
-
Make a request towards the ys ledger endpoint.
def starrail_diary_log(self, uid: Optional[int] = None, *, limit: Optional[int] = None, type: int = StarRailDiaryType.STELLARJADE, month: Optional[str] = None, lang: Optional[str] = None) ‑> genshin.client.components.diary.StarRailDiaryPaginator
-
Create a new daily reward paginator.
Inherited members