|
23 | 23 | '''
|
24 | 24 | import json
|
25 | 25 | from os import path
|
| 26 | +from .core import Client |
26 | 27 |
|
27 | 28 | _path = path.join(
|
28 | 29 | path.dirname(path.realpath(__file__)),
|
@@ -52,7 +53,11 @@ async def from_data(self):
|
52 | 53 |
|
53 | 54 | async def update(self):
|
54 | 55 | '''Update an object with current info.'''
|
55 |
| - data = await self.client.request(self.url) |
| 56 | + if self.client.session.closed: |
| 57 | + async with Client() as client: |
| 58 | + data = await client.request(self.url) |
| 59 | + else: |
| 60 | + data = await self.client.request(self.url) |
56 | 61 |
|
57 | 62 | self.raw_data = data
|
58 | 63 | self.from_data(data)
|
@@ -144,6 +149,8 @@ def __repr__(self):
|
144 | 149 | return '<Member tag={0.tag}>'.format(self)
|
145 | 150 |
|
146 | 151 | def get_profile(self):
|
| 152 | + if self.client.session.closed: |
| 153 | + return crasync.get_profile(self.tag) |
147 | 154 | return self.client.get_profile(self.tag)
|
148 | 155 |
|
149 | 156 | class Alliance:
|
@@ -206,7 +213,10 @@ def badge_url(self):
|
206 | 213 | return "http://api.cr-api.com" + url
|
207 | 214 |
|
208 | 215 | def get_clan(self):
|
209 |
| - return self.client.get_clan(self.tag) |
| 216 | + if self.client.session.closed: |
| 217 | + return crasync.get_clan(self.tag) |
| 218 | + else: |
| 219 | + return self.client.get_clan(self.tag) |
210 | 220 |
|
211 | 221 | def __repr__(self):
|
212 | 222 | return '<ClanInfo tag={0.tag}>'.format(self)
|
@@ -311,7 +321,10 @@ def get_chest(self, index=0):
|
311 | 321 | def get_clan(self):
|
312 | 322 | if self.clan_tag is None:
|
313 | 323 | raise ValueError('Profile has no Clan')
|
314 |
| - return self.client.get_clan(self.clan_tag) |
| 324 | + if self.client.session.closed: |
| 325 | + return crasync.get_clan(self.clan_tag) |
| 326 | + else: |
| 327 | + return self.client.get_clan(self.clan_tag) |
315 | 328 |
|
316 | 329 | def __repr__(self):
|
317 | 330 | return '<Profile tag={0.tag}>'.format(self)
|
|
0 commit comments