Skip to content

Base models

base models for this API wrapper client

After

Holds the after string

Source code in pyclasher/api/models/base_models.py
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
class After:
    """
    Holds the after string
    """

    def __init__(self, after):
        self._data = after
        return

    @property
    def value(self):
        return self._data

    def __repr__(self):
        return f"After(value={self.value})"

    def __str__(self):
        return f"After({self.value})"

value: str property

value of the after model

:return: the value of the after model :rtype: str

__init__(after)

initialisation of the after model

:return: None :rtype: None

Source code in pyclasher/api/models/base_models.py
64
65
66
def __init__(self, after):
    self._data = after
    return

BadgeUrl

Bases: ImageUrl

class to hold an url for one badge

Source code in pyclasher/api/models/base_models.py
111
112
class BadgeUrl(ImageUrl):
    pass

BadgeUrls

Bases: BaseModel

class to hold data of a clan badge

Source code in pyclasher/api/models/base_models.py
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
class BadgeUrls(BaseModel):
    @property
    def small(self):
        return BadgeUrl(self._get_data('small'))

    @property
    def medium(self):
        return BadgeUrl(self._get_data('medium'))

    @property
    def large(self):
        return BadgeUrl(self._get_data('large'))

    def __str__(self):
        return f"{self.__class__.__name__}({self.medium})"

large: BadgeUrl property

large badge URL

:return: the large badge URL :rtype: BadgeUrl

medium: BadgeUrl property

medium badge URL

:return: the medium badge URL :rtype: BadgeUrl

small: BadgeUrl property

small badge URL

:return: the small badge URL :rtype: BadgeUrl

BaseClan

Bases: BaseModel

base clan model

Source code in pyclasher/api/models/base_models.py
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
class BaseClan(BaseModel):
    @property
    def tag(self):
        return self._get_data('tag')

    @property
    def name(self):
        return self._get_data('name')

    @property
    def badge_urls(self):
        return BadgeUrls(self._get_data('badgeUrls'))

    def __str__(self):
        return f"{self.__class__. __name__}({self.tag})"

badge_urls: BadgeUrls property

clan badge URLs

:return: the clan's badge URLs :rtype: BadgeUrls

name: str property

clan name

:return: the clan's name :rtype: str

tag: str property

clan tag

:return: the clan's tag :rtype: str

BaseClanMember

Bases: BaseModel

base clan member model

Source code in pyclasher/api/models/base_models.py
270
271
272
273
274
275
276
277
278
279
280
class BaseClanMember(BaseModel):
    @property
    def tag(self):
        return self._get_data('tag')

    @property
    def name(self):
        return self._get_data('name')

    def __str__(self):
        return f"{self.__class__.__name__}({self.tag})"

name: str property

clan member's name

:return: the clan member's name :rtype: str

tag: str property

clan member's tag

:return: the clan member's tag :rtype: str

BaseLeague

Bases: BaseModel

base league model

Source code in pyclasher/api/models/base_models.py
283
284
285
286
287
288
289
290
291
292
293
class BaseLeague(BaseModel):
    @property
    def id(self):
        return self._get_data('id')

    @property
    def name(self):
        return self._get_data('name')

    def __str__(self):
        return f"{self.__class__.__name__}({self.id})"

id: int property

league id

:return: the league id :rtype: int

name: str property

league name

:return: the league name :rtype: str

Before

before model

Source code in pyclasher/api/models/base_models.py
79
80
81
82
83
84
85
86
87
88
89
90
91
92
class Before:
    def __init__(self, before):
        self._data = before
        return

    @property
    def value(self):
        return self._data

    def __repr__(self):
        return "Before()"

    def __str__(self):
        return f"Before(value={self.value})"

value: str property

value of the before model

:return: the value of the before model :rtype: str

__init__(before)

initialisation of the before model

:return: None :rtype: None

Source code in pyclasher/api/models/base_models.py
80
81
82
def __init__(self, before):
    self._data = before
    return

Cursor

Bases: BaseModel

cursor model

Source code in pyclasher/api/models/base_models.py
 95
 96
 97
 98
 99
100
101
102
class Cursor(BaseModel):
    @property
    def after(self):
        return After(self._get_data('after'))

    @property
    def before(self):
        return Before(self._get_data('before'))

IconUrl

Bases: ImageUrl

Holds an icon url

Source code in pyclasher/api/models/base_models.py
37
38
class IconUrl(ImageUrl):
    pass

IconUrls

Bases: BaseModel

icon URLs model that contains 3 icon URLs

Source code in pyclasher/api/models/base_models.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class IconUrls(BaseModel):
    def __init__(self, data: dict):
        super().__init__(data)
        return

    @property
    def tiny(self):
        return IconUrl(self._get_data('tiny'))

    @property
    def small(self):
        return IconUrl(self._get_data('small'))

    @property
    def medium(self):
        return IconUrl(self._get_data('medium'))

medium: IconUrl | MISSING property

medium icon URL

:return: the medium icon URL or MISSING if the medium icon URL is not supported for a model :rtype: str | Missing

small: IconUrl property

small icon URL

:return: the small icon URL :rtype: str

tiny: Missing | IconUrl property

tiny icon URL

:return: the tiny icon URL or MISSING if the tiny icon URL is not supported for a model :rtype: Missing | IconUrl

ImageUrl

image URL model

:ivar __url: URL of the image :type __url: str

Source code in pyclasher/api/models/base_models.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class ImageUrl:
    def __init__(self, url):
        self.__url = url
        return

    async def get_image(self, logger=MISSING) -> bytes:
        async with ClientSession() as session:
            async with session.get(self.url) as request:
                if request.status == 200:
                    logger.info(f"Successfully downloaded {self.url}")
                    return await request.read()

    async def save_image(self, filename, logger=MISSING):
        image = await self.get_image(logger)
        with open(filename, "wb") as file:
            file.write(image)

    @property
    def url(self):
        return self.__url

    def __repr__(self):
        return f"{self.__class__.__name__}(url={self.__url})"

    def __str__(self):
        return f"{self.__class__.__name__}({self.__url})"

url: str property

URL of the image

:return: the URL of the image :rtype: str

__init__(url)

initialisation of the image url model

Source code in pyclasher/api/models/base_models.py
10
11
12
def __init__(self, url):
    self.__url = url
    return

save_image(filename, logger=MISSING) async

NOT IMPLEMENTED YET

coroutine that retrieves the image of the URL

Source code in pyclasher/api/models/base_models.py
21
22
23
24
async def save_image(self, filename, logger=MISSING):
    image = await self.get_image(logger)
    with open(filename, "wb") as file:
        file.write(image)

Paging

Bases: BaseModel

Holds information about the paging of the clan war log

Source code in pyclasher/api/models/base_models.py
105
106
107
108
class Paging(BaseModel):
    @property
    def cursor(self) -> Cursor:
        return Cursor(self._get_data('cursors'))

Time

time model

:cvar time_format: time format of the string class method :type time_format: str :ivar _year: year of the date and time :type _year: int :ivar _month: month of the date and time :type _month: int :ivar _day: day of the date and time :type _day: int :ivar _hour: hour of the date and time :type _hour: int :ivar _minute: minute of the date and time :type _minute: int :ivar _second: second of the date and time :type _second: int :ivar _microsecond: microsecond of the date and time :type _microsecond: int

Source code in pyclasher/api/models/base_models.py
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
class Time:
    time_format = "%Y%m%dT%H%M%S.%fZ"

    def __init__(self, year, month, day, hour, minute, second, microsecond):
        self._year = year
        self._month = month
        self._day = day
        self._hour = hour
        self._minute = minute
        self._second = second
        self._microsecond = microsecond
        return

    @property
    def year(self):
        return self._year

    @property
    def month(self):
        return self._month

    @property
    def day(self):
        return self._day

    @property
    def hour(self):
        return self._hour

    @property
    def minute(self):
        return self._minute

    @property
    def second(self):
        return self._second

    @property
    def microsecond(self):
        return self._microsecond

    @classmethod
    def from_str(cls, time):
        try:
            dt = datetime.strptime(time, cls.time_format)
        except ValueError:
            raise InvalidTimeFormat(time, cls.time_format)

        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)
        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 NotImplemented

    def __ne__(self, other):
        return not self == other

    def __lt__(self, other):
        if isinstance(other, (Time, datetime)):
            if self._year < other.year:
                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):
                return True
            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):
                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):
                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
                    and self._microsecond < other.microsecond):
                return True
            return False
        return NotImplemented

    def __le__(self, other):
        return self == other or self < other

    def __gt__(self, other):
        return not self <= other

    def __ge__(self, other):
        return not self < other

    def __str__(self):
        return (f"Time({self._year}.{self._month}.{self._day}:"
                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}, "
                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,
                        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,
                        self._microsecond - other.microsecond)
        return NotImplemented

day: int property

day of the date and time

:return: the day of the date and time :rtype: int

hour: int property

hour of the date and time

:return: the hour of the date and time :rtype: int

microsecond: int property

microsecond of the date and time

:return: the microsecond of the date and time :rtype: int

minute: int property

minute of the date and time

:return: the minute of the date and time :rtype: int

month: int property

month of the date and time

:return: the month of the date and time :rtype: int

second: int property

second of the date and time

:return: the second of the date and time :rtype: int

year: int property

year of the date and time

:return: the year of the date and time :rtype: int

__init__(year, month, day, hour, minute, second, microsecond)

initialisation of the time model

:param year: year of the date and time :type year: int :param month: month of the date and time :type month: int :param day: day of the date and time :type day: int :param hour: hour of the date and time :type hour: int :param minute: minute of the date and time :type minute: int :param second: second of the date and time :type second: int :param microsecond: microsecond of the date and time :type microsecond: int

Source code in pyclasher/api/models/base_models.py
135
136
137
138
139
140
141
142
143
def __init__(self, year, month, day, hour, minute, second, microsecond):
    self._year = year
    self._month = month
    self._day = day
    self._hour = hour
    self._minute = minute
    self._second = second
    self._microsecond = microsecond
    return

from_str(time) classmethod

class method that converts a string with the format yyyymmddThhmmss.000Z

:param time: the time string following the format '%Y%m%dT%H%M%S.%fZ' :type time: str :return: a Time instance :rtype: Time :raise InvalidTimeFormat: raises InvalidTimeFormat if the time does not match the format '%Y%m%dT%H%M%S.%fZ'

Source code in pyclasher/api/models/base_models.py
173
174
175
176
177
178
179
180
181
182
183
@classmethod
def from_str(cls, time):
    try:
        dt = datetime.strptime(time, cls.time_format)
    except ValueError:
        raise InvalidTimeFormat(time, cls.time_format)

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