Module genshin.client.components.diary

Diary component.

Classes

class DiaryClient (cookies: ForwardRef('http.cookies.BaseCookie[Any]') | Mapping[Any, Any] | str | Sequence[ForwardRef('http.cookies.BaseCookie[Any]') | Mapping[Any, Any] | str] | None = None,
*,
authkey: str | None = None,
lang: str = 'en-us',
region: Region = Region.OVERSEAS,
proxy: str | None = None,
game: Game | None = None,
uid: int | None = None,
hoyolab_id: int | None = None,
device_id: str | None = None,
device_fp: str | None = None,
headers: Mapping[str, str] | Mapping[multidict._multidict.istr, str] | multidict._multidict.CIMultiDict | multidict._multidict.CIMultiDictProxy | Iterable[Tuple[str | multidict._multidict.istr, str]] | None = None,
cache: BaseCache | None = None,
debug: bool = False)
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,
        )

Diary component.

Ancestors

Subclasses

Class variables

var logger : logging.Logger

Instance variables

var authkeys : dict[Game, str]
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,
        )
var cacheBaseCache
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,
        )
var cookie_managerBaseCookieManager
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,
        )
var custom_headers : multidict._multidict.CIMultiDict[str]
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,
        )
var uids : dict[Game, int]
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,
        )

Methods

def diary_log(self,
uid: int | None = None,
*,
limit: int | None = None,
type: int = DiaryType.PRIMOGEMS,
month: int | None = None,
lang: str | None = None) ‑> genshin.client.components.diary.DiaryPaginator
Expand source code
@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,
    )

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: int | None = None,
*,
limit: int | None = None,
type: int = DiaryType.PRIMOGEMS,
month: int | None = None,
lang: str | None = None) ‑> genshin.client.components.diary.DiaryPaginator
Expand source code
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,
    )

Create a new daily reward paginator.

async def get_diary(self, uid: int | None = None, *, month: int | None = None, lang: str | None = None) ‑> Diary
Expand source code
@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)

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: int | None = None, *, month: int | None = None, lang: str | None = None) ‑> Diary
Expand source code
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)

Get a traveler's diary with earning details for the month.

async def get_starrail_diary(self, uid: int | None = None, *, month: int | None = None, lang: str | None = None) ‑> StarRailDiary
Expand source code
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)

Get a blazer's diary with earning details for the month.

async def request_ledger(self,
uid: int | None = None,
*,
game: Game | None = None,
detail: bool = False,
month: int | str | None = None,
lang: str | None = None,
params: Mapping[str, Any] | None = None,
**kwargs: Any) ‑> Mapping[str, Any]
Expand source code
@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)

Make a request towards the ys ledger endpoint.

def starrail_diary_log(self,
uid: int | None = None,
*,
limit: int | None = None,
type: int = StarRailDiaryType.STELLARJADE,
month: str | None = None,
lang: str | None = None) ‑> genshin.client.components.diary.StarRailDiaryPaginator
Expand source code
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,
    )

Create a new daily reward paginator.

Inherited members