EnkaNetwork.py/enkanetwork/model/base.py

65 lines
1.9 KiB
Python
Raw Normal View History

2022-11-19 05:36:05 +00:00
from pydantic import BaseModel, Field
from typing import List
from .players import PlayerInfo
from .character import CharacterInfo
from .profile import ProfilePatreon, ProfileOwner
from .hoyos import PlayerHoyos
from ..utils import BASE_URL
from typing import Any
2022-11-19 05:36:05 +00:00
__all__ = ("EnkaNetworkResponse",)
class EnkaNetworkInfo(BaseModel):
2023-02-07 08:28:37 +00:00
""" Enka.Network response data
Attributes
------------
uid: :class:`str`
UID Player
url: :class:`str`
URL to Enka.Network profile
path: :class:`str`
Path to enter Enka.network profile
"""
uid: str = ""
url: str = ""
path: str = ""
2022-11-19 05:36:05 +00:00
class EnkaNetworkResponse(BaseModel):
2023-02-07 08:28:37 +00:00
""" Enka.Network response data
Attributes
------------
player: :class:`PlayerInfo`
Player info data. Please refers in `PlayerInfo` class (key: "playerInfo")
characters: List[:class:`CharacterInfo`]
List character. Please refers in `CharacterInfo` class (key: "avatarInfoList")
profile: :class:`EnkaNetworkInfo`
profile enka.network. Please refers in `EnkaNetworkInfo` class
owner: :class:`ProfileOwner`
Owner UID data. **subscriptions in Enka.Network**. Please refers in `ProfileOwner` class
ttl: :class:`int`
Cache timeout
uid: :class:`int`
UID Player
"""
2022-11-19 05:36:05 +00:00
player: PlayerInfo = Field(None, alias="playerInfo")
characters: List[CharacterInfo] = Field(None, alias="avatarInfoList")
profile: EnkaNetworkInfo = EnkaNetworkInfo()
owner: ProfileOwner = None
ttl: int = 0
2023-02-07 08:28:37 +00:00
uid: int = 0
def __init__(self, **data: Any) -> None:
super().__init__(**data)
self.profile.path = f"/u/{data.get('uid')}"
self.profile.url = BASE_URL.format(PATH=self.profile.path[1:])
self.profile.uid = data.get("uid") or ""
class EnkaNetworkProfileResponse(BaseModel):
username: str
profile: ProfilePatreon
hoyos: List[PlayerHoyos] = []