2023-05-05 04:06:43 +00:00
|
|
|
from functools import partial
|
|
|
|
from typing import Optional, List
|
|
|
|
|
2023-05-05 12:04:41 +00:00
|
|
|
from simnet.client.components.wish.base import BaseWishClient
|
2023-05-05 04:06:43 +00:00
|
|
|
from simnet.models.genshin.wish import Wish
|
|
|
|
from simnet.utils.enum_ import Game
|
|
|
|
from simnet.utils.paginator import WishPaginator
|
|
|
|
|
2023-05-05 12:04:41 +00:00
|
|
|
__all__ = ("GenshinWishClient",)
|
|
|
|
|
|
|
|
|
|
|
|
class GenshinWishClient(BaseWishClient):
|
|
|
|
"""The GenshinWishClient class for making requests towards the Wish API."""
|
2023-05-05 04:06:43 +00:00
|
|
|
|
|
|
|
async def wish_history(
|
|
|
|
self,
|
2023-05-08 00:53:48 +00:00
|
|
|
banner_types: Optional[List[int]] = None,
|
2023-05-05 04:06:43 +00:00
|
|
|
limit: Optional[int] = None,
|
|
|
|
lang: Optional[str] = None,
|
|
|
|
authkey: Optional[str] = None,
|
|
|
|
end_id: int = 0,
|
|
|
|
) -> List[Wish]:
|
2023-05-08 00:53:48 +00:00
|
|
|
"""Get the wish history for a list of banner types.
|
2023-05-05 04:06:43 +00:00
|
|
|
|
|
|
|
Args:
|
2023-05-08 00:53:48 +00:00
|
|
|
banner_types (Optional[List[int]], optional): The banner types to get the wish history for.
|
2023-05-05 04:06:43 +00:00
|
|
|
limit (Optional[int] , optional): The maximum number of wishes to retrieve.
|
|
|
|
If not provided, all available wishes will be returned.
|
|
|
|
lang (Optional[str], optional): The language code to use for the request.
|
|
|
|
If not provided, the class default will be used.
|
|
|
|
authkey (Optional[str], optional): The authorization key for making the request.
|
|
|
|
end_id (int, optional): The ending ID of the last wish to retrieve.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
List[Wish]: A list of GenshinWish objects representing the retrieved wishes.
|
|
|
|
"""
|
2023-05-08 00:53:48 +00:00
|
|
|
banner_types = banner_types or [100, 200, 301, 302]
|
2023-05-12 03:24:06 +00:00
|
|
|
banner_names = await self.get_banner_names(game=Game.GENSHIN, lang=lang, authkey=authkey)
|
2023-05-08 00:53:48 +00:00
|
|
|
wishes = []
|
|
|
|
for banner_type in banner_types:
|
|
|
|
paginator = WishPaginator(
|
|
|
|
end_id,
|
|
|
|
partial(
|
|
|
|
self.get_wish_page,
|
|
|
|
banner_type=banner_type,
|
|
|
|
game=Game.GENSHIN,
|
|
|
|
authkey=authkey,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
items = await paginator.get(limit)
|
|
|
|
banner_name = banner_names[banner_type]
|
|
|
|
wishes.extend([Wish(**i, banner_name=banner_name) for i in items])
|
|
|
|
return sorted(wishes, key=lambda wish: wish.time.timestamp())
|