Skip to content

Commit 4ca113b

Browse files
committed
Add a new class: LeagueWarLogEntry to specify a war log entry from a league season
1 parent eec9972 commit 4ca113b

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

coc/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
LeaguePlayer,
3131
LeagueClan,
3232
LeagueGroup,
33-
LeagueWar
33+
LeagueWar,
34+
LeagueWarLogEntry
3435
)
3536
from .errors import (
3637
ClashOfClansException,

coc/dataclasses.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ def __init__(self, *, data, war):
220220
self.total_attacks = self._war.team_size * 2
221221
self.stars = data.get('stars')
222222
self.max_stars = self._war.team_size * 3
223-
self.destruction = []
224223

225224
for mdata in data.get('members', []):
226225
member = WarMember(data=mdata, war=self._war)
@@ -1151,3 +1150,45 @@ class LeagueWar(CurrentWar):
11511150
def __init__(self, *, data):
11521151
self.tag = data.get('tag', None)
11531152
super(LeagueWar, self).__init__(data=data)
1153+
1154+
1155+
class LeagueWarLogEntry:
1156+
"""Represents a Clash of Clans War Log entry for a League Season
1157+
1158+
Attributes
1159+
-----------
1160+
end_time:
1161+
:class:`Timestamp` - The end time of the war as a Timestamp object
1162+
team_size:
1163+
:class:`int` - The number of players per clan in war
1164+
clan:
1165+
:class:`Clan` - The offensive clan. Note this is only a :class:`Clan`, unlike that of a :class:`WarLog`
1166+
enemy_stars:
1167+
:class:`int` - Total enemy stars for all wars
1168+
attack_count:
1169+
:class:`int` - The total attacks completed by your clan over all wars
1170+
stars:
1171+
:class:`int` The total stars by your clan over all wars
1172+
destruction:
1173+
:class:`float` - The total destruction by your clan over all wars
1174+
clan_level:
1175+
:class:`int` - Your clan level.
1176+
"""
1177+
1178+
__slots__ = ('end_time', 'team_size', 'clan', 'enemy_stars',
1179+
'attack_count', 'stars', 'destruction', 'clan_level')
1180+
1181+
def __init__(self, *, data):
1182+
self.end_time = try_enum(Timestamp, data.get('endTime'))
1183+
self.team_size = data.get('teamSize')
1184+
self.clan = try_enum(Clan, data.get('clan'))
1185+
try:
1186+
self.enemy_stars = data['opponent']['stars']
1187+
except KeyError:
1188+
self.enemy_stars = None
1189+
1190+
if self.clan:
1191+
self.attack_count = self.clan._data.get('attacks')
1192+
self.stars = self.clan._data.get('stars')
1193+
self.destruction = self.clan._data.get('destructionPercentag')
1194+
self.clan_level = self.clan._data.get('clanLevel')

docs/api.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ League War Objects
171171
:members:
172172
:inherited-members:
173173

174-
174+
.. autoclass:: LeagueWarLogEntry()
175+
:members:
175176

176177

177178
Exceptions

0 commit comments

Comments
 (0)