Skip to content

Commit

Permalink
Merge pull request #34 from Jylpah/dev
Browse files Browse the repository at this point in the history
version 1.2.6: WGApi: get_tank_stats(): update Region logic
  • Loading branch information
Jylpah authored Jan 18, 2024
2 parents c12726d + 5cc8f96 commit e496f66
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 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.5"
version = "1.2.6"
authors = [{ name = "Jylpah", email = "[email protected]" }]
description = "Pydantic models for Wargaming's World of Tanks Blitz game "
readme = "README.md"
Expand Down
24 changes: 10 additions & 14 deletions src/blitzmodels/wg_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,22 +986,18 @@ def get_tank_stats_url(
tank_ids: list[int] = [],
fields: list[str] = [],
) -> Tuple[str, Region] | None:
assert isinstance(account_id, int), "account_id must be int"
assert isinstance(tank_ids, list), "tank_ids must be a list"
assert isinstance(fields, list), "fields must be a list"
# assert isinstance(account_id, int), "account_id must be int"
# assert isinstance(tank_ids, list), "tank_ids must be a list"
# assert isinstance(fields, list), "fields must be a list"
try:
URL_WG_TANK_STATS: str = "tanks/stats/"

account_region: Region = Region.from_id(account_id)

if region is not None and account_region != region:
raise ValueError(
f"account_id {account_id} does not match region {region.name}"
)
if region is None:
region = Region.from_id(account_id)

server: str | None = self.get_server_url(account_region)
server: str | None = self.get_server_url(region)
if server is None:
raise ValueError(f"No API server for region {account_region.value}")
raise ValueError(f"No API server for region {region.value}")

tank_id_str: str = ""
if len(tank_ids) > 0:
Expand All @@ -1018,7 +1014,7 @@ def get_tank_stats_url(
# else:
return (
f"{server}{URL_WG_TANK_STATS}?application_id={self.app_id}&account_id={account_id}{tank_id_str}{field_str}",
account_region,
region,
)
except Exception as err:
debug(f"Failed to form url for account_id: {account_id}: {err}")
Expand All @@ -1031,7 +1027,7 @@ async def get_tank_stats_full(
tank_ids: list[int] = [],
fields: list[str] = [],
) -> WGApiWoTBlitzTankStats | None:
assert isinstance(region, Region), "region must be type of Region"
# assert isinstance(region, Region), "region must be type of Region"
try:
if region is None:
region = Region.from_id(account_id)
Expand Down Expand Up @@ -1209,7 +1205,7 @@ async def get_player_achievements_full(
region: Region,
fields: list[str] = list(),
) -> WGApiWoTBlitzPlayerAchievements | None:
assert isinstance(region, Region), "region must be type of Region"
# assert isinstance(region, Region), "region must be type of Region"
try:
url: str | None
if (
Expand Down

0 comments on commit e496f66

Please sign in to comment.