Skip to content

Commit 94cde6a

Browse files
Merge pull request #208 from mathsman5133/g10_3.0.0
v3.0.0 big update
2 parents bdf2b51 + 251508c commit 94cde6a

File tree

83 files changed

+634038
-493
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+634038
-493
lines changed

coc/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
SOFTWARE.
2323
"""
2424

25-
__version__ = "2.4.2"
25+
__version__ = "3.0.0"
2626

2727
from .abc import BasePlayer, BaseClan
2828
from .clans import RankedClan, Clan
@@ -54,7 +54,6 @@
5454
GatewayError,
5555
PrivateWarLog,
5656
)
57-
from .login import login, login_with_keys
5857
from .hero import Hero, Pet
5958
from .http import BasicThrottler, BatchThrottler, HTTPClient
6059
from .iterators import (
@@ -78,7 +77,7 @@
7877
Timestamp,
7978
TimeDelta,
8079
Label,
81-
WarLeague,
80+
BaseLeague
8281
)
8382
from .players import Player, ClanMember, RankedPlayer
8483
from .player_clan import PlayerClan

coc/abc.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def _load_json_meta(cls, troop_meta, id, name, lab_to_townhall):
193193
cls.hitpoints = try_enum(UnitStat, troop_meta.get("Hitpoints"))
194194

195195
# get production building
196-
production_building = troop_meta.get("ProductionBuilding", [None])[0]
196+
production_building = troop_meta.get("ProductionBuilding", [None])[0] if troop_meta.get("ProductionBuilding") else None
197197
if production_building == "Barrack":
198198
cls.is_elixir_troop = True
199199
elif production_building == "Dark Elixir Barrack":
@@ -326,11 +326,13 @@ class DataContainerHolder:
326326
def __init__(self):
327327
self.loaded = False
328328

329-
def _load_json(self, object_ids, english_aliases, lab_to_townhall):
329+
def _load_json(self, english_aliases, lab_to_townhall):
330330
with open(self.FILE_PATH) as fp:
331331
data = ujson.load(fp)
332332

333+
id = 2000
333334
for c, [supercell_name, meta] in enumerate(data.items()):
335+
334336
# Not interested if it doesn't have a TID, since it likely isn't a real troop.
335337
if not meta.get("TID"):
336338
continue
@@ -340,8 +342,12 @@ def _load_json(self, object_ids, english_aliases, lab_to_townhall):
340342
continue
341343

342344
# SC game files have "DisableProduction" true for all pet objects, which we want
343-
if "DisableProduction" in meta and "pets" not in str(
344-
self.FILE_PATH):
345+
if True in meta.get("DisableProduction", [False]) and "pets" not in str(self.FILE_PATH):
346+
continue
347+
348+
#hacky but the aliases convert so that isnt great
349+
IGNORED_PETS = ["Unused", "PhoenixEgg"]
350+
if "pets" in str(self.FILE_PATH) and supercell_name in IGNORED_PETS:
345351
continue
346352

347353
# A bit of a hacky way to create a "copy" of a new Troop object that hasn't been initiated yet.
@@ -350,11 +356,11 @@ def _load_json(self, object_ids, english_aliases, lab_to_townhall):
350356
dict(self.data_object.__dict__))
351357
new_item._load_json_meta(
352358
meta,
353-
id=object_ids.get(supercell_name, c),
354-
name=english_aliases[meta["TID"][0]][0],
359+
id=id,
360+
name=english_aliases[meta["TID"][0]]["EN"][0],
355361
lab_to_townhall=lab_to_townhall,
356362
)
357-
363+
id += 1
358364
self.items.append(new_item)
359365
self.item_lookup[new_item.name] = new_item
360366

coc/clans.py

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626

2727
from .players import ClanMember
28-
from .miscmodels import try_enum, ChatLanguage, Location, Label, WarLeague, CapitalDistrict
28+
from .miscmodels import try_enum, ChatLanguage, Location, Label, BaseLeague, CapitalDistrict
2929
from .utils import get, cached_property, correct_tag
3030
from .abc import BaseClan
3131

@@ -48,11 +48,13 @@ class RankedClan(BaseClan):
4848
member_count: :class:`int`
4949
The number of members in the clan.
5050
points: :class:`int`
51-
The clan's trophy-count. If retrieving info for capital or versus leader-boards, this will be ``None``.
52-
versus_points: :class:`int`
53-
The clan's versus trophy count. If retrieving info for regular or capital leader boards, this will be ``None``.
51+
The clan's trophy-count. If retrieving info for capital or builder base leader-boards, this will be ``None``.
52+
builder_base_points: :class:`int`
53+
The clan's builder base trophy count. If retrieving info for regular or capital leader boards, this will be
54+
``None``.
5455
capital_points: :class:`int`
55-
The clan's capital trophy count. If retrieving info for regular or versus leader boards, this will be ``None``.
56+
The clan's capital trophy count. If retrieving info for regular or builder base leader boards, this will be
57+
``None``.
5658
rank: :class:`int`
5759
The clan's rank in the leader board.
5860
previous_rank: :class:`int`
@@ -63,7 +65,7 @@ class RankedClan(BaseClan):
6365
"location",
6466
"member_count",
6567
"points",
66-
"versus_points",
68+
"builder_base_points",
6769
"capital_points",
6870
"rank",
6971
"previous_rank",
@@ -77,7 +79,7 @@ def _from_data(self, data: dict) -> None:
7779
data_get = data.get
7880

7981
self.points: int = data_get("clanPoints")
80-
self.versus_points: int = data_get("clanVersusPoints")
82+
self.builder_base_points: int = data_get("clanBuilderBasePoints")
8183
self.capital_points: int = data_get("clanCapitalPoints")
8284
self.member_count: int = data_get("members")
8385
self.location = try_enum(Location, data=data_get("location"))
@@ -110,12 +112,14 @@ class Clan(BaseClan):
110112
The clan's location.
111113
points: :class:`int`
112114
The clan's trophy count. This is calculated according to members' trophy counts.
113-
versus_points: :class:`int`
114-
The clan's versus trophy count. This is calculated according to members' versus trophy counts.
115+
builder_base_points: :class:`int`
116+
The clan's builder base trophy count. This is calculated according to members' builder base trophy counts.
115117
capital_points: :class:`int`
116118
The clan's clan capital points. Unsure how this is calculated.
117119
required_trophies: :class:`int`
118120
The minimum trophies required to apply to this clan.
121+
required_builder_base_trophies: :class:`int`
122+
The minimum builder base trophies required to apply to this clan.
119123
required_townhall: :class:`int`
120124
The minimum townhall level required to apply to this clan.
121125
war_frequency: :class:`str`
@@ -126,9 +130,9 @@ class Clan(BaseClan):
126130
war_wins: :class:`int`
127131
The number of wars the clan has won.
128132
war_ties: :class:`int`
129-
The number of wars the clan has tied.
133+
The number of wars the clan has tied. This is only available from the clan search endpoint else -1.
130134
war_losses: :class:`int`
131-
The number of wars the clan has lost.
135+
The number of wars the clan has lost. This is only available from the clan search endpoint else -1.
132136
public_war_log: :class:`bool`
133137
Indicates if the clan has a public war log.
134138
If this is ``False``, operations to find the clan's current
@@ -145,9 +149,9 @@ class Clan(BaseClan):
145149
The type which the clan capital districts found in
146150
:attr:`Clan.capital_districts` will be of. Ensure any overriding of
147151
this inherits from :class:`coc.CapitalDistrict`.
148-
war_league: :class:`coc.WarLeague`
152+
war_league: :class:`coc.BaseLeague`
149153
The clan's CWL league.
150-
capital_league: :class:`coc.WarLeague`
154+
capital_league: :class:`coc.BaseLeague`
151155
The clan's Clan Capital league.
152156
"""
153157

@@ -157,9 +161,10 @@ class Clan(BaseClan):
157161
"description",
158162
"location",
159163
"points",
160-
"versus_points",
164+
"builder_base_points",
161165
"capital_points",
162166
"required_trophies",
167+
"required_builder_base_trophies",
163168
"war_frequency",
164169
"war_win_streak",
165170
"war_wins",
@@ -200,7 +205,7 @@ def _from_data(self, data: dict) -> None:
200205
data_get = data.get
201206

202207
self.points: int = data_get("clanPoints")
203-
self.versus_points: int = data_get("clanVersusPoints")
208+
self.builder_base_points: int = data_get("clanBuilderBasePoints")
204209
self.capital_points: int = data_get("clanCapitalPoints")
205210
self.member_count: int = data_get("members")
206211
self.location = try_enum(Location, data=data_get("location"))
@@ -209,15 +214,16 @@ def _from_data(self, data: dict) -> None:
209214
self.type: str = data_get("type")
210215
self.family_friendly = data_get("isFamilyFriendly")
211216
self.required_trophies: int = data_get("requiredTrophies")
217+
self.required_builder_base_trophies: int = data_get("requiredBuilderBaseTrophies")
212218
self.war_frequency: str = data_get("warFrequency")
213219
self.war_win_streak: int = data_get("warWinStreak")
214220
self.war_wins: int = data_get("warWins")
215-
self.war_ties: int = data_get("warTies")
216-
self.war_losses: int = data_get("warLosses")
221+
self.war_ties: int = data_get("warTies", -1)
222+
self.war_losses: int = data_get("warLosses", -1)
217223
self.public_war_log: bool = data_get("isWarLogPublic")
218224
self.description: str = data_get("description")
219-
self.war_league = try_enum(WarLeague, data=data_get("warLeague"))
220-
self.capital_league = try_enum(WarLeague, data=data_get("capitalLeague"))
225+
self.war_league = try_enum(BaseLeague, data=data_get("warLeague"))
226+
self.capital_league = try_enum(BaseLeague, data=data_get("capitalLeague"))
221227
self.chat_language = try_enum(ChatLanguage, data=data_get("chatLanguage"))
222228
self.required_townhall = data_get("requiredTownhallLevel")
223229

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

0 commit comments

Comments
 (0)