Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

version 1.2.7: add __len__() to WG API models #35

Merged
merged 3 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "blitz-models"
version = "1.2.6"
version = "1.2.7"
authors = [{ name = "Jylpah", email = "[email protected]" }]
description = "Pydantic models for Wargaming's World of Tanks Blitz game "
readme = "README.md"
Expand Down
22 changes: 22 additions & 0 deletions src/blitzmodels/wg_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,15 +441,32 @@ class WGApiWoTBlitzAccountInfo(WGApiWoTBlitz):
frozen=False, validate_assignment=True, populate_by_name=True
)

def __len__(self) -> int:
res: int = 0
if self.data is not None:
for v in self.data.values():
if v is not None:
res += 1
return res


class WGApiWoTBlitzTankStats(WGApiWoTBlitz):
"""Model for WG API /wotb/tanks/stats/"""

data: Dict[str, Optional[list[TankStat]]] | None = Field(default=None, alias="d")

model_config = ConfigDict(
frozen=False, validate_assignment=True, populate_by_name=True
)

def __len__(self) -> int:
if self.data is not None:
for v in self.data.values():
if v is not None:
return len(v)
break
return 0


class PlayerAchievements(JSONExportable):
"""Placeholder class for data.achievements that are not collected"""
Expand Down Expand Up @@ -622,6 +639,11 @@ def validate_data(
res = {key: value for key, value in v.items() if value is not None}
return res

def __len__(self) -> int:
if self.data is not None:
return len(self.data)
return 0

def get_max_series(self) -> list[PlayerAchievementsMaxSeries]:
res: list[PlayerAchievementsMaxSeries] = list()
try:
Expand Down
2 changes: 1 addition & 1 deletion src/blitzmodels/wotinspector/wi_apiv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def validate_none(cls, value: str | None) -> str:
else:
return value

@field_validator("team", "time_alive", mode="before")
@field_validator("team", "time_alive", "death_reason", mode="before")
@classmethod
def validate_none_minus1(cls, value: str | None) -> str:
if value is None:
Expand Down