Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
33f849b
Remove depreciated login methods
doluk May 12, 2023
2806d53
Bump version number
doluk May 12, 2023
5ed489c
add new endpoints and rename old ones
doluk May 12, 2023
2d01b37
remove depreciated methods from import
doluk May 12, 2023
72f6cb9
Update versus to builder base
doluk May 12, 2023
3219ead
rename logs
Kuchenmampfer May 16, 2023
98fc7d7
fix typo
Kuchenmampfer May 19, 2023
258b6da
Add new mock data for clans
doluk May 29, 2023
c40d1e9
added default values for warTies, warLoses to deal with search clans …
doluk May 29, 2023
7646549
Write full tests for all attributes given directly by the api
doluk May 29, 2023
9044c35
Add clantag to mock data
doluk May 29, 2023
6cdf9e8
Write a full test for raid seasons
doluk May 29, 2023
cbb7e6d
Start migrating_to_v3.rst
doluk May 29, 2023
186f734
Add changelog entry
doluk May 29, 2023
941e297
Extend raidseason tests to cover all properties coc.py supports
doluk May 29, 2023
30d8d25
fix missing attribute _cs_raid_attacks
doluk May 29, 2023
657d61b
Merge branch 'master' into g10_3.0.0
Kuchenmampfer May 30, 2023
4c0a0da
Merge remote-tracking branch 'cocpy_main/g10_3.0.0' into g10_3.0.0
Kuchenmampfer May 30, 2023
425f8f9
bump version
Kuchenmampfer May 30, 2023
f291adc
Revamp mock data to a more non python approach, Update tests to still…
doluk Jun 6, 2023
55b2fc2
New Static Files & Rework
Magic-Jr Jun 20, 2023
73eeb17
remove print
Magic-Jr Jun 20, 2023
6fb49ed
Update __init__.py
Magic-Jr Jun 20, 2023
2fc66c4
Update pyproject.toml
Magic-Jr Jun 20, 2023
583ada9
Merge pull request #204 from Magic-Jr/master
doluk Jun 20, 2023
7eee8fb
clean up object ids
doluk Jun 22, 2023
20d0c20
clean up object ids
doluk Jun 22, 2023
6baa5a2
update examples
doluk Jun 22, 2023
c84050e
add builder base league
doluk Jun 22, 2023
e08d8dc
add player house elements at correct base class level
doluk Jun 22, 2023
dba3006
update requirements.txt for new static file origin
doluk Jun 22, 2023
6b14ada
remove versus trophies test
doluk Jun 22, 2023
51ffce9
remove object ids dependency
doluk Jun 22, 2023
37121ae
add blank line at file end
doluk Jun 22, 2023
6f420d4
add doluk as maintainer
doluk Jun 22, 2023
f8fd5d8
Fix BuilderBaseLeague
doluk Jun 22, 2023
eddfb8e
add BuilderBaseLeague
doluk Jun 22, 2023
e782f92
bump version
doluk Jun 22, 2023
03edd8f
prevent circular import
doluk Jun 22, 2023
189aba6
Add stars property to RaidDistricts
doluk Jul 11, 2023
269e26a
add builder base league endpoints to client
Kuchenmampfer Jul 11, 2023
b44212b
rename the hopefully last internal xxxlogs to xxx_logs
Kuchenmampfer Jul 11, 2023
f75939a
remove incorrect documentation
Kuchenmampfer Jul 11, 2023
d378fb3
add back triggers extension that somehow got lost in the weeds
Kuchenmampfer Jul 11, 2023
abc2a95
write migration guide
Kuchenmampfer Jul 11, 2023
0c83742
improve migration guide and include it in the docs
Kuchenmampfer Jul 11, 2023
3acf162
Rewrite League and BaseLeague, fix Player.get_pet()
doluk Jul 12, 2023
18eaf38
Add example for importing a client from one file everywhere
doluk Jul 12, 2023
c4285a0
Add new example to docs
doluk Jul 12, 2023
251508c
finish up the migration guide and put *something* into the acknowledg…
Kuchenmampfer Jul 12, 2023
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
5 changes: 2 additions & 3 deletions coc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
SOFTWARE.
"""

__version__ = "2.4.2"
__version__ = "3.0.0"

from .abc import BasePlayer, BaseClan
from .clans import RankedClan, Clan
Expand Down Expand Up @@ -54,7 +54,6 @@
GatewayError,
PrivateWarLog,
)
from .login import login, login_with_keys
from .hero import Hero, Pet
from .http import BasicThrottler, BatchThrottler, HTTPClient
from .iterators import (
Expand All @@ -78,7 +77,7 @@
Timestamp,
TimeDelta,
Label,
WarLeague,
BaseLeague
)
from .players import Player, ClanMember, RankedPlayer
from .player_clan import PlayerClan
Expand Down
20 changes: 13 additions & 7 deletions coc/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def _load_json_meta(cls, troop_meta, id, name, lab_to_townhall):
cls.hitpoints = try_enum(UnitStat, troop_meta.get("Hitpoints"))

# get production building
production_building = troop_meta.get("ProductionBuilding", [None])[0]
production_building = troop_meta.get("ProductionBuilding", [None])[0] if troop_meta.get("ProductionBuilding") else None
if production_building == "Barrack":
cls.is_elixir_troop = True
elif production_building == "Dark Elixir Barrack":
Expand Down Expand Up @@ -326,11 +326,13 @@ class DataContainerHolder:
def __init__(self):
self.loaded = False

def _load_json(self, object_ids, english_aliases, lab_to_townhall):
def _load_json(self, english_aliases, lab_to_townhall):
with open(self.FILE_PATH) as fp:
data = ujson.load(fp)

id = 2000
for c, [supercell_name, meta] in enumerate(data.items()):

# Not interested if it doesn't have a TID, since it likely isn't a real troop.
if not meta.get("TID"):
continue
Expand All @@ -340,8 +342,12 @@ def _load_json(self, object_ids, english_aliases, lab_to_townhall):
continue

# SC game files have "DisableProduction" true for all pet objects, which we want
if "DisableProduction" in meta and "pets" not in str(
self.FILE_PATH):
if True in meta.get("DisableProduction", [False]) and "pets" not in str(self.FILE_PATH):
continue

#hacky but the aliases convert so that isnt great
IGNORED_PETS = ["Unused", "PhoenixEgg"]
if "pets" in str(self.FILE_PATH) and supercell_name in IGNORED_PETS:
continue

# A bit of a hacky way to create a "copy" of a new Troop object that hasn't been initiated yet.
Expand All @@ -350,11 +356,11 @@ def _load_json(self, object_ids, english_aliases, lab_to_townhall):
dict(self.data_object.__dict__))
new_item._load_json_meta(
meta,
id=object_ids.get(supercell_name, c),
name=english_aliases[meta["TID"][0]][0],
id=id,
name=english_aliases[meta["TID"][0]]["EN"][0],
lab_to_townhall=lab_to_townhall,
)

id += 1
self.items.append(new_item)
self.item_lookup[new_item.name] = new_item

Expand Down
48 changes: 27 additions & 21 deletions coc/clans.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


from .players import ClanMember
from .miscmodels import try_enum, ChatLanguage, Location, Label, WarLeague, CapitalDistrict
from .miscmodels import try_enum, ChatLanguage, Location, Label, BaseLeague, CapitalDistrict
from .utils import get, cached_property, correct_tag
from .abc import BaseClan

Expand All @@ -48,11 +48,13 @@ class RankedClan(BaseClan):
member_count: :class:`int`
The number of members in the clan.
points: :class:`int`
The clan's trophy-count. If retrieving info for capital or versus leader-boards, this will be ``None``.
versus_points: :class:`int`
The clan's versus trophy count. If retrieving info for regular or capital leader boards, this will be ``None``.
The clan's trophy-count. If retrieving info for capital or builder base leader-boards, this will be ``None``.
builder_base_points: :class:`int`
The clan's builder base trophy count. If retrieving info for regular or capital leader boards, this will be
``None``.
capital_points: :class:`int`
The clan's capital trophy count. If retrieving info for regular or versus leader boards, this will be ``None``.
The clan's capital trophy count. If retrieving info for regular or builder base leader boards, this will be
``None``.
rank: :class:`int`
The clan's rank in the leader board.
previous_rank: :class:`int`
Expand All @@ -63,7 +65,7 @@ class RankedClan(BaseClan):
"location",
"member_count",
"points",
"versus_points",
"builder_base_points",
"capital_points",
"rank",
"previous_rank",
Expand All @@ -77,7 +79,7 @@ def _from_data(self, data: dict) -> None:
data_get = data.get

self.points: int = data_get("clanPoints")
self.versus_points: int = data_get("clanVersusPoints")
self.builder_base_points: int = data_get("clanBuilderBasePoints")
self.capital_points: int = data_get("clanCapitalPoints")
self.member_count: int = data_get("members")
self.location = try_enum(Location, data=data_get("location"))
Expand Down Expand Up @@ -110,12 +112,14 @@ class Clan(BaseClan):
The clan's location.
points: :class:`int`
The clan's trophy count. This is calculated according to members' trophy counts.
versus_points: :class:`int`
The clan's versus trophy count. This is calculated according to members' versus trophy counts.
builder_base_points: :class:`int`
The clan's builder base trophy count. This is calculated according to members' builder base trophy counts.
capital_points: :class:`int`
The clan's clan capital points. Unsure how this is calculated.
required_trophies: :class:`int`
The minimum trophies required to apply to this clan.
required_builder_base_trophies: :class:`int`
The minimum builder base trophies required to apply to this clan.
required_townhall: :class:`int`
The minimum townhall level required to apply to this clan.
war_frequency: :class:`str`
Expand All @@ -126,9 +130,9 @@ class Clan(BaseClan):
war_wins: :class:`int`
The number of wars the clan has won.
war_ties: :class:`int`
The number of wars the clan has tied.
The number of wars the clan has tied. This is only available from the clan search endpoint else -1.
war_losses: :class:`int`
The number of wars the clan has lost.
The number of wars the clan has lost. This is only available from the clan search endpoint else -1.
public_war_log: :class:`bool`
Indicates if the clan has a public war log.
If this is ``False``, operations to find the clan's current
Expand All @@ -145,9 +149,9 @@ class Clan(BaseClan):
The type which the clan capital districts found in
:attr:`Clan.capital_districts` will be of. Ensure any overriding of
this inherits from :class:`coc.CapitalDistrict`.
war_league: :class:`coc.WarLeague`
war_league: :class:`coc.BaseLeague`
The clan's CWL league.
capital_league: :class:`coc.WarLeague`
capital_league: :class:`coc.BaseLeague`
The clan's Clan Capital league.
"""

Expand All @@ -157,9 +161,10 @@ class Clan(BaseClan):
"description",
"location",
"points",
"versus_points",
"builder_base_points",
"capital_points",
"required_trophies",
"required_builder_base_trophies",
"war_frequency",
"war_win_streak",
"war_wins",
Expand Down Expand Up @@ -200,7 +205,7 @@ def _from_data(self, data: dict) -> None:
data_get = data.get

self.points: int = data_get("clanPoints")
self.versus_points: int = data_get("clanVersusPoints")
self.builder_base_points: int = data_get("clanBuilderBasePoints")
self.capital_points: int = data_get("clanCapitalPoints")
self.member_count: int = data_get("members")
self.location = try_enum(Location, data=data_get("location"))
Expand All @@ -209,15 +214,16 @@ def _from_data(self, data: dict) -> None:
self.type: str = data_get("type")
self.family_friendly = data_get("isFamilyFriendly")
self.required_trophies: int = data_get("requiredTrophies")
self.required_builder_base_trophies: int = data_get("requiredBuilderBaseTrophies")
self.war_frequency: str = data_get("warFrequency")
self.war_win_streak: int = data_get("warWinStreak")
self.war_wins: int = data_get("warWins")
self.war_ties: int = data_get("warTies")
self.war_losses: int = data_get("warLosses")
self.war_ties: int = data_get("warTies", -1)
self.war_losses: int = data_get("warLosses", -1)
self.public_war_log: bool = data_get("isWarLogPublic")
self.description: str = data_get("description")
self.war_league = try_enum(WarLeague, data=data_get("warLeague"))
self.capital_league = try_enum(WarLeague, data=data_get("capitalLeague"))
self.war_league = try_enum(BaseLeague, data=data_get("warLeague"))
self.capital_league = try_enum(BaseLeague, data=data_get("capitalLeague"))
self.chat_language = try_enum(ChatLanguage, data=data_get("chatLanguage"))
self.required_townhall = data_get("requiredTownhallLevel")

Expand All @@ -227,8 +233,8 @@ def _from_data(self, data: dict) -> None:
# update members globally. only available via /clans/{clanTag}
member_cls = self.member_cls
member_data = data.get("memberList", [])
for rank, mdata in enumerate(sorted(member_data, key=lambda x: x["versusTrophies"], reverse=True), 1):
mdata["versusRank"] = rank
for rank, mdata in enumerate(sorted(member_data, key=lambda x: x["builderBaseTrophies"], reverse=True), 1):
mdata["builderBaseRank"] = rank
self._iter_members = (
member_cls(data=mdata, client=self._client, clan=self) for mdata in member_data
)
Expand Down
Loading