mirror of
https://github.com/PaiGramTeam/EnkaNetwork.py.git
synced 2024-11-16 03:45:28 +00:00
Update model:
- Add model for fetch profile (Hoyos, Build) - Add model profile enka UID
This commit is contained in:
parent
eaab479b8b
commit
fc7bfe02ec
@ -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
|
@ -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")
|
||||
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] = []
|
43
enkanetwork/model/build.py
Normal file
43
enkanetwork/model/build.py
Normal file
@ -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)
|
17
enkanetwork/model/hoyos.py
Normal file
17
enkanetwork/model/hoyos.py
Normal file
@ -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
|
||||
|
||||
|
16
enkanetwork/model/profile.py
Normal file
16
enkanetwork/model/profile.py
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user