Skip to content

Commit

Permalink
Merge pull request #34 from 201st-Luka/new-features
Browse files Browse the repository at this point in the history
New features
  • Loading branch information
201st-Luka authored Aug 24, 2023
2 parents fcfbd3a + 94d76b0 commit 3a4aa11
Show file tree
Hide file tree
Showing 32 changed files with 246 additions and 778 deletions.
664 changes: 3 additions & 661 deletions .editorconfig

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions pyclasher/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
from .client import Client

# exceptions.py
from .exceptions import (Missing, MISSING, PyClasherException, ApiCode, RequestNotDone, NoneToken, InvalidLoginData,
InvalidType, LoginNotDone, ClientIsRunning, ClientIsNotRunning, ClientAlreadyInitialised,
NoClient, InvalidTimeFormat, ClientRunningOverwrite, InvalidSeasonFormat, RequestTimeout)
from .exceptions import (
Missing, MISSING, PyClasherException, ApiCode, RequestNotDone, NoneToken,
InvalidLoginData, InvalidType, LoginNotDone, ClientIsRunning,
ClientIsNotRunning, ClientAlreadyInitialised, NoClient,
InvalidTimeFormat, ClientRunningOverwrite, InvalidSeasonFormat,
RequestTimeout
)
16 changes: 12 additions & 4 deletions pyclasher/api/bulk_requests/b_request_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ def requests(self):
return self._requests

def __get_properties(self):
return {name: prop.__get__(self) for name, prop in vars(self.__class__).items() if isinstance(prop, property)}
return {
name: prop.__get__(self)
for name, prop in vars(self.__class__).items()
if isinstance(prop, property)
}

async def _async_request(self):
self._tasks = [request.request() for request in self._requests]
Expand All @@ -38,7 +42,8 @@ def __getitem__(self, item):
if isinstance(item, int):
return self._requests[item]
if isinstance(item, slice):
return (self._requests[i] for i in range(*item.indices(len(self._requests))))
return (self._requests[i]
for i in range(*item.indices(len(self._requests))))
raise NotImplementedError

def __iter__(self):
Expand All @@ -52,5 +57,8 @@ def __str__(self):
return f"{self.__class__.__name__}({self._main_attribute})"

def __repr__(self):
return (f"{self.__class__.__name__}"
f"({', '.join(('='.join((key, str(value))) for key, value in self.__get_properties().items()))})")
props = ', '.join(
('='.join((key, str(value)))
for key, value in self.__get_properties().items())
)
return f"{self.__class__.__name__}({props})"
73 changes: 52 additions & 21 deletions pyclasher/api/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,79 @@
# abc
from .abc import BaseModel, IterBaseModel
# base models, miscellaneous models and enums
from .base_models import ImageUrl, IconUrl, IconUrls, After, Before, \
Cursor, Paging, BadgeUrl, BadgeUrls, Time, BaseClanMember, BaseClan, BaseLeague
from .base_models import (
ImageUrl, IconUrl, IconUrls, After, Before,
Cursor, Paging, BadgeUrl, BadgeUrls, Time,
BaseClanMember, BaseClan,
BaseLeague
)
# clan models
from .clan import ClanDistrictData, ClanDistrictDataList, ClanCapital, Clan
from .clan_builder_base_ranking_list import ClanBuilderBaseRanking, ClanBuilderBaseRankingList
from .clan_capital_raid_seasons import ClanCapitalRaidSeasonClanInfo, ClanCapitalRaidSeasonAttacker, \
ClanCapitalRaidSeasonAttack, ClanCapitalRaidSeasonAttackList, ClanCapitalRaidSeasonDistrict, \
ClanCapitalRaidSeasonDistrictList, ClanCapitalRaidSeasonDefenseLogEntry, ClanCapitalRaidSeasonAttackLogEntry, \
ClanCapitalRaidSeasonDefenseLogList, ClanCapitalRaidSeasonAttackLogList, ClanCapitalRaidSeasonMember, \
ClanCapitalRaidSeasonMemberList, ClanCapitalRaidSeason, ClanCapitalRaidSeasons
from .clan_capital_ranking_list import ClanCapitalRanking, ClanCapitalRankingList
from .clan_builder_base_ranking_list import (
ClanBuilderBaseRanking, ClanBuilderBaseRankingList
)
from .clan_capital_raid_seasons import (
ClanCapitalRaidSeasonClanInfo, ClanCapitalRaidSeasonAttacker,
ClanCapitalRaidSeasonAttack, ClanCapitalRaidSeasonAttackList,
ClanCapitalRaidSeasonDistrict, ClanCapitalRaidSeasonDistrictList,
ClanCapitalRaidSeasonDefenseLogEntry,
ClanCapitalRaidSeasonAttackLogEntry, ClanCapitalRaidSeasonDefenseLogList,
ClanCapitalRaidSeasonAttackLogList, ClanCapitalRaidSeasonMember,
ClanCapitalRaidSeasonMemberList, ClanCapitalRaidSeason,
ClanCapitalRaidSeasons
)
from .clan_capital_ranking_list import (
ClanCapitalRanking, ClanCapitalRankingList
)
from .clan_list import ClanList
from .clan_member import ClanMember
from .clan_member_list import ClanMemberList
from .clan_ranking_list import ClanRanking, ClanRankingList
from .clan_war import ClanWar
from .clan_war_league_group import ClanWarLeagueRound, ClanWarLeagueRoundList, ClanWarLeagueClanMember, \
ClanWarLeagueClanMemberList, ClanWarLeagueClan, ClanWarLeagueClanList, ClanWarLeagueGroup
from .clan_war_league_group import (
ClanWarLeagueRound, ClanWarLeagueRoundList, ClanWarLeagueClanMember,
ClanWarLeagueClanMemberList, ClanWarLeagueClan, ClanWarLeagueClanList,
ClanWarLeagueGroup
)
from .clan_war_log import ClanWarLogEntry, ClanWarLog
from .enums import ApiCodes, ClanType, WarFrequency, Locations, Leagues, CapitalLeagues, \
BuilderBaseLeagues, WarLeagues, Labels, Languages, ClanWarState, ClanWarLeagueGroupState, \
ClanWarResult, WarPreference, PlayerHouseElementType, Village, TokenStatus, ClanRole
from .enums import (
ApiCodes, ClanType, WarFrequency, Locations, Leagues, CapitalLeagues,
BuilderBaseLeagues, WarLeagues, Labels, Languages, ClanWarState,
ClanWarLeagueGroupState, ClanWarResult, WarPreference,
PlayerHouseElementType, Village, TokenStatus, ClanRole
)
# gold pass season
from .gold_pass_season import GoldPassSeason
# labels
from .labels import Label, LabelList
from .language import Language
# league models
from .leagues import League, BuilderBaseLeague, CapitalLeague, WarLeague, LeagueList, \
BuilderBaseLeagueList, CapitalLeagueList, WarLeagueList, LeagueSeason, LeagueSeasonList
from .leagues import (
League, BuilderBaseLeague, CapitalLeague, WarLeague, LeagueList,
BuilderBaseLeagueList, CapitalLeagueList, WarLeagueList, LeagueSeason,
LeagueSeasonList
)
# locations
from .location import Location, LocationList
# login
from .login import *
from .misc import *
# player models
from .player import PlayerClan, LegendLeagueTournamentSeasonResult, PlayerLegendStatistics, \
PlayerItemLevel, PlayerItemLevelList, PlayerAchievementProgress, PlayerAchievementProgressList, Player
from .player_builder_base_ranking_list import PlayerBuilderBaseRanking, PlayerBuilderBaseRankingList
from .player_house import PlayerHouseElement, PlayerHouseElementList, PlayerHouse
from .player import (
PlayerClan, LegendLeagueTournamentSeasonResult, PlayerLegendStatistics,
PlayerItemLevel, PlayerItemLevelList, PlayerAchievementProgress,
PlayerAchievementProgressList, Player
)
from .player_builder_base_ranking_list import (
PlayerBuilderBaseRanking, PlayerBuilderBaseRankingList
)
from .player_house import (
PlayerHouseElement, PlayerHouseElementList, PlayerHouse
)
from .player_ranking_clan import PlayerRankingClan
from .player_ranking_list import PlayerRanking, PlayerRankingList
# misc
from .season import Season
from .war_clan import ClanWarAttack, ClanWarAttackList, ClanWarMember, ClanWarMemberList, WarClan
from .war_clan import (
ClanWarAttack, ClanWarAttackList, ClanWarMember, ClanWarMemberList, WarClan
)
22 changes: 16 additions & 6 deletions pyclasher/api/models/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ def to_dict(self):

def _get_properties(self):
if isinstance(self._data, dict):
return {name: prop.__get__(self) for name, prop in vars(type(self)).items() if isinstance(prop, property)}
return {
name: prop.__get__(self)
for name, prop in vars(type(self)).items()
if isinstance(prop, property)
}
return self._data

def _get_data(self, item):
Expand All @@ -39,8 +43,11 @@ def __str__(self):
return f"{self.__class__.__name__}()"

def __repr__(self):
return (f"{self.__class__.__name__}"
f"({', '.join(('='.join((key, str(value))) for key, value in self._get_properties().items()))})")
props = ', '.join(
('='.join((key, str(value)))
for key, value in self._get_properties().items())
)
return f"{self.__class__.__name__}({props})"


class IterBaseModel(ABC):
Expand Down Expand Up @@ -72,8 +79,10 @@ def __getitem__(self, item):
if isinstance(item, int):
return self._iter_rtype(self._data[item])
if isinstance(item, slice):
return (self._iter_rtype(self._data[i]) for i in range(*item.indices(len(self._data))))
raise NotImplementedError(f"there is no implementation for type {item.__class__.__name__} in "
return (self._iter_rtype(self._data[i])
for i in range(*item.indices(len(self._data))))
raise NotImplementedError(f"there is no implementation for type "
f"{item.__class__.__name__} in "
f"{self.__class__.__name__}.__getitem__()")

def __iter__(self):
Expand All @@ -95,7 +104,8 @@ def __str__(self):
return f"{self.__class__.__name__}()"

def __repr__(self):
return f"{self.__class__.__name__}(len={self._len}, type={self._iter_rtype.__name__}, {list(self)})"
return (f"{self.__class__.__name__}(len={self._len}, type="
f"{self._iter_rtype.__name__}, {list(self)})")



60 changes: 40 additions & 20 deletions pyclasher/api/models/base_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,22 @@ def from_str(cls, time):
except ValueError:
raise InvalidTimeFormat(time, cls.time_format)

return cls(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.microsecond)
return cls(
dt.year, dt.month, dt.day,
dt.hour, dt.minute, dt.second, dt.microsecond
)

def __eq__(self, other):
if isinstance(other, Time):
return self._year == other._year and self._month == other._month and self._day == other._day and \
self._hour == other._hour and self._minute == other._minute and self._second == other._second
return (self._year == other._year and self._month == other._month
and self._day == other._day and
self._hour == other._hour and self._minute == other._minute
and self._second == other._second)
if isinstance(other, (Time, datetime)):
return self._year == other.year and self._month == other.month and self._day == other.day and \
self._hour == other.hour and self._minute == other.minute and self._second == other.second
return (self._year == other.year and self._month == other.month
and self._day == other.day and
self._hour == other.hour and self._minute == other.minute
and self._second == other.second)
return NotImplemented

def __ne__(self, other):
Expand All @@ -189,19 +196,26 @@ def __lt__(self, other):
return True
if self._year == other.year and self._month < other.month:
return True
if self._year == other.year and self._month == other.month and self._day < other.day:
if (self._year == other.year and self._month == other.month
and self._day < other.day):
return True
if (self._year == other.year and self._month == other.month and self._day == other.day
if (self._year == other.year and self._month == other.month
and self._day == other.day
and self._hour < other.hour):
return True
if (self._year == other.year and self._month == other.month and self._day == other.day
and self._hour == other.hour and self._minute < other.minute):
if (self._year == other.year and self._month == other.month
and self._day == other.day and self._hour == other.hour
and self._minute < other.minute):
return True
if (self._year == other.year and self._month == other.month and self._day == other.day
and self._hour == other.hour and self._minute == other.minute and self._second < other.second):
if (self._year == other.year and self._month == other.month
and self._day == other.day and self._hour == other.hour
and self._minute == other.minute
and self._second < other.second):
return True
if (self._year == other.year and self._month == other.month and self._day == other.day
and self._hour == other.hour and self._minute == other.minute and self._second == other.second
if (self._year == other.year and self._month == other.month
and self._day == other.day and self._hour == other.hour
and self._minute == other.minute
and self._second == other.second
and self._microsecond < other.microsecond):
return True
return False
Expand All @@ -218,23 +232,29 @@ def __ge__(self, other):

def __str__(self):
return (f"Time({self._year}.{self._month}.{self._day}:"
f"{self._hour}.{self._minute}.{self._second}.{self._microsecond})")
f"{self._hour}.{self._minute}.{self._second}"
f".{self._microsecond})")

def __repr__(self):
return (f"Time(year={self._year}, month={self._month}, day={self._day}, "
f"hour={self._hour}, minute={self._minute}, second={self._second}, microsecond={self._microsecond})")
return (f"Time(year={self._year}, month={self._month}, day={self._day},"
f" hour={self._hour}, minute={self._minute}, "
f"second={self._second}, microsecond={self._microsecond})")

def __add__(self, other):
if isinstance(other, (Time, datetime)):
return Time(self._year + other.year, self._month + other.month, self._day + other.day,
self._hour + other.hour, self._minute + other.minute, self._second + other.second,
return Time(self._year + other.year, self._month + other.month,
self._day + other.day, self._hour + other.hour,
self._minute + other.minute,
self._second + other.second,
self._microsecond + other.microsecond)
return NotImplemented

def __sub__(self, other):
if isinstance(other, (Time, datetime)):
return Time(self._year - other.year, self._month - other.month, self._day - other.day,
self._hour - other.hour, self._minute - other.minute, self._second - other.second,
return Time(self._year - other.year, self._month - other.month,
self._day - other.day, self._hour - other.hour,
self._minute - other.minute,
self._second - other.second,
self._microsecond - other.microsecond)
return NotImplemented

Expand Down
24 changes: 18 additions & 6 deletions pyclasher/api/models/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,39 @@ def best_season(self):

@property
def current_season(self):
return LegendLeagueTournamentSeasonResult(self._get_data('currentSeason'))
return LegendLeagueTournamentSeasonResult(
self._get_data('currentSeason')
)

@property
def previous_season(self):
return LegendLeagueTournamentSeasonResult(self._get_data('previousSeason'))
return LegendLeagueTournamentSeasonResult(
self._get_data('previousSeason')
)

@property
def previous_builder_base_season(self):
return LegendLeagueTournamentSeasonResult(self._get_data('previousBuilderBaseSeason'))
return LegendLeagueTournamentSeasonResult(
self._get_data('previousBuilderBaseSeason')
)

@property
def previous_versus_season(self):
return LegendLeagueTournamentSeasonResult(self._get_data('previousVersusSeason'))
return LegendLeagueTournamentSeasonResult(
self._get_data('previousVersusSeason')
)

@property
def best_builder_base_season(self):
return LegendLeagueTournamentSeasonResult(self._get_data('bestBuilderBaseSeason'))
return LegendLeagueTournamentSeasonResult(
self._get_data('bestBuilderBaseSeason')
)

@property
def best_versus_season(self):
return LegendLeagueTournamentSeasonResult(self._get_data('bestVersusSeason'))
return LegendLeagueTournamentSeasonResult(
self._get_data('bestVersusSeason')
)

@property
def legend_trophies(self):
Expand Down
6 changes: 3 additions & 3 deletions pyclasher/api/requests/abc.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from abc import ABC
from logging import Logger
from typing import Any, Coroutine, Iterator, Generator
from typing import Any, Iterator, Generator

from ..models import Paging
from ...client import RequestMethods, Client
from ...client import Client
from ...utils import RequestMethods
from ...exceptions import MISSING, Missing

request_id: int = 0
Expand Down
4 changes: 2 additions & 2 deletions pyclasher/api/requests/builder_base_leagues.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, limit=None, after=None, before=None):
self._main_attribute = self._len
return

async def request(self):
await super().request()
async def request(self, client_id=None):
await super().request(client_id)
self._main_attribute = len(self)
return self
3 changes: 0 additions & 3 deletions pyclasher/api/requests/builder_base_leagues.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ class BuilderBaseLeaguesRequest(IterRequestModel):
def __init__(self, limit: int = None, after: str = None, before: str = None):
...

async def _async_request(self) -> BuilderBaseLeaguesRequest:
...

def items(self) -> _list_rtype:
...

Expand Down
2 changes: 0 additions & 2 deletions pyclasher/api/requests/clan.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from asyncio import get_running_loop, run

from .abc import RequestModel
from ..models import Clan, BaseClan

Expand Down
2 changes: 0 additions & 2 deletions pyclasher/api/requests/clan_current_war.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from asyncio import get_running_loop, run

from .abc import RequestModel
from ..models import ClanWar, BaseClan

Expand Down
2 changes: 0 additions & 2 deletions pyclasher/api/requests/clan_current_war.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Coroutine, Any

from .abc import RequestModel
from ..models import ClanWar, BaseClan

Expand Down
Loading

0 comments on commit 3a4aa11

Please sign in to comment.