Skip to content
This repository was archived by the owner on Aug 19, 2018. It is now read-only.

Commit 15c283f

Browse files
committed
fixed coed
1 parent a3bf8f3 commit 15c283f

File tree

2 files changed

+18
-34
lines changed

2 files changed

+18
-34
lines changed

crasync/core.py

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import aiohttp
22
import asyncio
3-
from .models import Profile, Clan, Clans, Constants
3+
from .models import Profile, Clan, Constants
44

55

66
class Client:
@@ -28,41 +28,29 @@ async def get_profile(self, tag):
2828
if resp.status == 200:
2929
data = await resp.json()
3030
else:
31-
print('API is down. Please be patient.')
32-
return None
31+
raise ConnectionError(f'API not responding: {resp.status}')
3332

3433
return Profile(self, data)
35-
36-
async def get_clans(self, *, tags):
34+
35+
async def get_clan(self, *tags):
3736
'''Get a clan object using tag(s)'''
38-
tags = tags.split(',')
39-
40-
if len(tags) == 1:
41-
url = f'{self.BASE}/clan/{tags[0]}'
42-
async with self.session.get(url) as resp:
43-
if resp.status == 200:
44-
data = await resp.json()
45-
else:
46-
print('API is down. Please be patient.')
47-
return None
48-
return Clan(self, data)
49-
50-
taglist = ''
51-
i = 0
52-
for tag in tags:
53-
i += 1
54-
taglist += tag[1:]
55-
if i != len(tags):
56-
taglist += ','
57-
58-
url = f'{self.BASE}/clan/{taglist}'
37+
38+
tags = ','.join(tags)
39+
40+
url = f'{self.BASE}/clan/{tags}'
41+
5942
async with self.session.get(url) as resp:
6043
if resp.status == 200:
6144
data = await resp.json()
6245
else:
63-
print('API is down. Please be patient.')
64-
return None
65-
return Clans(self, data)
46+
raise ConnectionError(f'API not responding: {resp.status}')
47+
48+
if isinstance(data, list):
49+
return [Clan(self, c) for c in data]
50+
else:
51+
return Clan(self, c)
52+
53+
get_clans = get_clan
6654

6755
async def get_constants(self):
6856
'''Get a profile object using a tag.'''
@@ -73,8 +61,7 @@ async def get_constants(self):
7361
if resp.status == 200:
7462
data = await resp.json()
7563
else:
76-
print('API is down. Please be patient.')
77-
return None
64+
raise ConnectionError(f'API not responding: {resp.status}')
7865

7966
return Constants(self, data)
8067

crasync/models.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,6 @@ def badge_url(self):
173173
def __repr__(self):
174174
return f'<Clan tag={self.tag}>'
175175

176-
class Clans(Base):
177-
def from_data(self, data):
178-
self.clans = [Clan(self.client, c) for c in data]
179176

180177
class Profile(Base):
181178
'''Represents a player profile.

0 commit comments

Comments
 (0)