Skip to content

Commit

Permalink
Merge pull request #35 from Jylpah/dev
Browse files Browse the repository at this point in the history
version 1.2.7: add `__len__()` to WG API models
  • Loading branch information
Jylpah authored Jan 20, 2024
2 parents e496f66 + f2446fd commit 52a45d2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
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

0 comments on commit 52a45d2

Please sign in to comment.