From fc7bfe02ecf6e8e45f72ca92ab988c88b582500f Mon Sep 17 00:00:00 2001 From: "M307 (Mac)" Date: Mon, 6 Feb 2023 22:02:46 +0700 Subject: [PATCH] Update model: - Add model for fetch profile (Hoyos, Build) - Add model profile enka UID --- enkanetwork/enum.py | 5 +++++ enkanetwork/model/base.py | 26 +++++++++++++++++++++- enkanetwork/model/build.py | 43 ++++++++++++++++++++++++++++++++++++ enkanetwork/model/hoyos.py | 17 ++++++++++++++ enkanetwork/model/profile.py | 16 ++++++++++++++ 5 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 enkanetwork/model/build.py create mode 100644 enkanetwork/model/hoyos.py create mode 100644 enkanetwork/model/profile.py diff --git a/enkanetwork/enum.py b/enkanetwork/enum.py index 7f8bdb7..d7e2b12 100644 --- a/enkanetwork/enum.py +++ b/enkanetwork/enum.py @@ -61,3 +61,8 @@ class EquipType(str, Enum): Sands = "EQUIP_SHOES" Goblet = "EQUIP_RING" Circlet = "EQUIP_DRESS" + +class ProfileRank(int, Enum): + TIER_1 = 1 + TIER_2 = 2 + TIER_3 = 3 \ No newline at end of file diff --git a/enkanetwork/model/base.py b/enkanetwork/model/base.py index 137bad7..16719d3 100644 --- a/enkanetwork/model/base.py +++ b/enkanetwork/model/base.py @@ -3,10 +3,34 @@ 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 __all__ = ("EnkaNetworkResponse",) +class EnkaNetworkInfo(BaseModel): + uid: str = "" + url: str = "" + path: str = "" + class EnkaNetworkResponse(BaseModel): player: PlayerInfo = Field(None, alias="playerInfo") characters: List[CharacterInfo] = Field(None, alias="avatarInfoList") - ttl: int = 0 \ No newline at end of file + profile: EnkaNetworkInfo = EnkaNetworkInfo() + owner: ProfileOwner = None + ttl: 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] = [] \ No newline at end of file diff --git a/enkanetwork/model/build.py b/enkanetwork/model/build.py new file mode 100644 index 0000000..a3413c9 --- /dev/null +++ b/enkanetwork/model/build.py @@ -0,0 +1,43 @@ +from pydantic import BaseModel + +from .character import CharacterInfo + +from typing import Dict, List, Any + +class BuildInfo(BaseModel): + id: int + name: str = '' + avatar_id: str = '' + avatar_data: CharacterInfo + order: int = 0 + live: bool = False + settings: Dict[str, Any] = {} + public: bool = True + +class Builds(BaseModel): + raw: Dict[str, List[BuildInfo]] = {} + + def __init__(self, **data: Any) -> None: + _data = {} + for key in data: + _build = [] + for build in data[key]: + _build.append(build) + + _data[key] = _build + + super().__init__(**{"raw": _data}) + + def get_build_info(self, avatar_id: str, build_id: str): + buildList = self.raw.get(str(avatar_id), None) + if buildList is None: + return None + + for buildInfo in buildList: + if str(buildInfo.id) == build_id: + return buildInfo + + return None + + def get_character(self, avatar_id: str): + return self.raw.get(str(avatar_id), None) \ No newline at end of file diff --git a/enkanetwork/model/hoyos.py b/enkanetwork/model/hoyos.py new file mode 100644 index 0000000..671b968 --- /dev/null +++ b/enkanetwork/model/hoyos.py @@ -0,0 +1,17 @@ +from pydantic import BaseModel + +from .players import PlayerInfo +from .build import Builds + +class PlayerHoyos(BaseModel): + uid_public: bool = False + public: bool = False + verified: bool = False + player_info: PlayerInfo + hash: str + region: str + order: str + + builds: Builds = None + + \ No newline at end of file diff --git a/enkanetwork/model/profile.py b/enkanetwork/model/profile.py new file mode 100644 index 0000000..c12d758 --- /dev/null +++ b/enkanetwork/model/profile.py @@ -0,0 +1,16 @@ +from pydantic import BaseModel + +from ..enum import ProfileRank +from .build import Builds + +class ProfilePatreon(BaseModel): + bio: str = '' + level: ProfileRank = ProfileRank.TIER_1 + signup_state: int = 0 + image_url: str = '' + +class ProfileOwner(BaseModel): + hash: str + username: str + profile: ProfilePatreon + builds: Builds = None \ No newline at end of file