11import aiohttp
22import asyncio
3- from .models import Profile , Profiles , Clan , Clans , Constants
3+ from .models import Profile , Clan , Constants
44
55
66class Client :
@@ -20,38 +20,24 @@ def __init__(self, session=None):
2020
2121
2222 async def get_profile (self , * , tags ):
23- '''Get a profile object using tag(s).'''
24- tags = tags .split (',' )
23+ '''Get a profile object using tag(s)'''
2524
26- if len (tags ) == 1 :
27- url = f'{ self .BASE } /profile/{ tags [0 ]} '
28-
29- async with self .session .get (url ) as resp :
30- if resp .status == 200 :
31- data = await resp .json ()
32- else :
33- print ('API is down. Please be patient.' )
34- return None
35-
36- return Profile (self , data )
25+ tags = ',' .join (tags )
3726
38- taglist = ''
39- i = 0
40- for tag in tags :
41- i += 1
42- taglist += tag [1 :]
43- if i != len (tags ):
44- taglist += ','
27+ url = f'{ self .BASE } /profile/{ tags } '
4528
46- url = f'{ self .BASE } /profile/{ taglist } '
4729 async with self .session .get (url ) as resp :
4830 if resp .status == 200 :
4931 data = await resp .json ()
5032 else :
5133 raise ConnectionError (f'API not responding: { resp .status } ' )
52- return Profiles (self , data )
5334
54- async def get_clans (self , * , tags ):
35+ if isinstance (data , list ):
36+ return [Profile (self , c ) for c in data ]
37+ else :
38+ return Profile (self , data )
39+
40+ async def get_clan (self , * , tags ):
5541 '''Get a clan object using tag(s)'''
5642
5743 tags = ',' .join (tags )
@@ -67,7 +53,7 @@ async def get_clans(self, *, tags):
6753 if isinstance (data , list ):
6854 return [Clan (self , c ) for c in data ]
6955 else :
70- return Clan (self , c )
56+ return Clan (self , data )
7157
7258 get_clans = get_clan
7359
0 commit comments