Module genshin.client.components.wiki

Wiki component.

Classes

class WikiClient (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)

Wiki component.

Expand source code
class WikiClient(base.BaseClient):
    """Wiki component."""

    async def request_wiki(
        self,
        endpoint: str,
        *,
        lang: typing.Optional[str] = None,
        headers: typing.Optional[typing.Mapping[str, str]] = None,
        **kwargs: typing.Any,
    ) -> typing.Mapping[str, typing.Any]:
        """Make a request towards the wiki endpoint."""
        headers = dict(headers or {})

        url = routes.WIKI_URL.get_url() / endpoint
        headers["x-rpc-language"] = lang or self.lang

        return await self.request(url, headers=headers, **kwargs)

    @typing.overload
    async def get_wiki_previews(  # noqa: D102 missing docstring in overload?
        self,
        menu: typing.Literal[models.WikiPageType.CHARACTER],
        *,
        lang: typing.Optional[str] = None,
    ) -> typing.Sequence[models.CharacterPreview]: ...

    @typing.overload
    async def get_wiki_previews(  # noqa: D102 missing docstring in overload?
        self,
        menu: typing.Literal[models.WikiPageType.WEAPON],
        *,
        lang: typing.Optional[str] = None,
    ) -> typing.Sequence[models.WeaponPreview]: ...

    @typing.overload
    async def get_wiki_previews(  # noqa: D102 missing docstring in overload?
        self,
        menu: typing.Literal[models.WikiPageType.ARTIFACT],
        *,
        lang: typing.Optional[str] = None,
    ) -> typing.Sequence[models.ArtifactPreview]: ...

    @typing.overload
    async def get_wiki_previews(  # noqa: D102 missing docstring in overload?
        self,
        menu: typing.Literal[models.WikiPageType.ENEMY],
        *,
        lang: typing.Optional[str] = None,
    ) -> typing.Sequence[models.EnemyPreview]: ...

    @typing.overload
    async def get_wiki_previews(  # noqa: D102 missing docstring in overload?
        self,
        menu: int,
        *,
        lang: typing.Optional[str] = None,
    ) -> typing.Sequence[models.BaseWikiPreview]: ...

    async def get_wiki_previews(
        self,
        menu: int,
        *,
        lang: typing.Optional[str] = None,
    ) -> typing.Sequence[models.BaseWikiPreview]:
        """Get a list of wiki previews."""
        payload = dict(filters=[], menu_id=int(menu), page_num=1, page_size=1000, use_es=True)
        cache_key = cache.cache_key("wiki", endpoint="entry", menu=menu, lang=lang or self.lang)
        data = await self.request_wiki("get_entry_page_list", data=payload, lang=lang, static_cache=cache_key)

        cls = models._ENTRY_PAGE_MODELS.get(typing.cast(models.WikiPageType, menu), models.BaseWikiPreview)

        return [cls(**i) for i in data["list"] if i["icon_url"]]

    async def get_wiki_page(
        self,
        id: types.IDOr[models.BaseWikiPreview],
        *,
        lang: typing.Optional[str] = None,
    ) -> models.WikiPage:
        """Get a wiki page."""
        params = dict(entry_page_id=int(id))
        cache_key = cache.cache_key("wiki", endpoint="page", id=id, lang=lang or self.lang)
        data = await self.request_wiki("entry_page", lang=lang, params=params, static_cache=cache_key)

        data["page"].pop("lang", "")  # always an empty string
        return models.WikiPage(**data["page"])

    async def get_wiki_pages(
        self,
        ids: typing.Collection[types.IDOr[models.BaseWikiPreview]],
        *,
        lang: typing.Optional[str] = None,
    ) -> typing.Sequence[models.WikiPage]:
        """Get multiple wiki pages without modules."""
        payload = dict(entry_page_ids=[int(i) for i in ids])
        data = await self.request_wiki("entry_pages", lang=lang, data=payload)

        return [models.WikiPage(**i) for i in data["entry_pages"]]

Ancestors

Subclasses

Class variables

var logger : logging.Logger

Instance variables

var authkeys : dict[Game, str]
var cacheBaseCache
var cookie_managerBaseCookieManager
var custom_headers : multidict._multidict.CIMultiDict[str]
var uids : dict[Game, int]

Methods

async def get_wiki_page(self, id: Union[int, genshin.models.genshin.wiki.BaseWikiPreview], *, lang: Optional[str] = None) ‑> WikiPage

Get a wiki page.

async def get_wiki_pages(self, ids: Collection[Union[int, genshin.models.genshin.wiki.BaseWikiPreview]], *, lang: Optional[str] = None) ‑> Sequence[WikiPage]

Get multiple wiki pages without modules.

async def get_wiki_previews(self, menu: int, *, lang: Optional[str] = None) ‑> Sequence[genshin.models.genshin.wiki.BaseWikiPreview]

Get a list of wiki previews.

async def request_wiki(self, endpoint: str, *, lang: Optional[str] = None, headers: Optional[Mapping[str, str]] = None, **kwargs: Any) ‑> Mapping[str, Any]

Make a request towards the wiki endpoint.

Inherited members