Skip to content

Commit e8c14a9

Browse files
committed
Allow slow requests with fast client
1 parent 46c2947 commit e8c14a9

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

coc/client.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,12 @@ async def get_clan_war(self, clan_tag: str, cls: Type[ClanWar] = ClanWar, **kwar
589589
clan_tag = correct_tag(clan_tag)
590590

591591
try:
592-
data = await self.http.get_clan_current_war(clan_tag)
592+
realtime = kwargs.get("realtime")
593+
except KeyError:
594+
realtime = None
595+
596+
try:
597+
data = await self.http.get_clan_current_war(clan_tag, realtime=realtime)
593598
except Forbidden as exception:
594599
raise PrivateWarLog(exception.response, exception.reason) from exception
595600

@@ -696,7 +701,12 @@ async def get_league_group(
696701
clan_tag = correct_tag(clan_tag)
697702

698703
try:
699-
data = await self.http.get_clan_war_league_group(clan_tag)
704+
realtime = kwargs.get("realtime")
705+
except KeyError:
706+
realtime = None
707+
708+
try:
709+
data = await self.http.get_clan_war_league_group(clan_tag, realtime=realtime)
700710
except Forbidden as exception:
701711
raise PrivateWarLog(exception.response, exception.reason) from exception
702712
except asyncio.TimeoutError:
@@ -744,7 +754,12 @@ async def get_league_war(self, war_tag: str, cls: Type[ClanWar] = ClanWar, **kwa
744754
war_tag = correct_tag(war_tag)
745755

746756
try:
747-
data = await self.http.get_cwl_wars(war_tag)
757+
realtime = kwargs.get("realtime")
758+
except KeyError:
759+
realtime = None
760+
761+
try:
762+
data = await self.http.get_cwl_wars(war_tag, realtime=realtime)
748763
except Forbidden as exception:
749764
raise PrivateWarLog(exception.response, exception.reason) from exception
750765

@@ -872,7 +887,7 @@ async def get_current_war(
872887
return get_war
873888

874889
try:
875-
league_group = await self.get_league_group(clan_tag)
890+
league_group = await self.get_league_group(clan_tag,**kwargs)
876891
except (NotFound, GatewayError) as exception:
877892
# either they're not in cwl (NotFound)
878893
# or it's an API bug where league group endpoint will timeout when the clan is searching (GatewayError)

coc/http.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -345,17 +345,20 @@ def get_clan_members(self, tag):
345345
def get_clan_warlog(self, tag):
346346
return self.request(Route("GET", "/clans/{}/warlog".format(tag)))
347347

348-
def get_clan_current_war(self, tag):
349-
return self.request(Route("GET", "/clans/{}/currentwar".format(tag) +
350-
'?realtime=true' if self.client.realtime else ''))
351-
352-
def get_clan_war_league_group(self, tag):
353-
return self.request(Route("GET", "/clans/{}/currentwar/leaguegroup".format(tag) +
354-
'?realtime=true' if self.client.realtime else ''))
355-
356-
def get_cwl_wars(self, war_tag):
357-
return self.request(Route("GET", "/clanwarleagues/wars/{}".format(war_tag) +
358-
'?realtime=true' if self.client.realtime else ''))
348+
def get_clan_current_war(self, tag, realtime = None):
349+
return self.request(Route("GET", "/clans/{}/currentwar".format(tag) + (
350+
'?realtime=true' if realtime or (not realtime and self.client.realtime)
351+
else '')))
352+
353+
def get_clan_war_league_group(self, tag, realtime = None):
354+
return self.request(Route("GET", "/clans/{}/currentwar/leaguegroup".format(tag) + (
355+
'?realtime=true' if realtime or (not realtime and self.client.realtime)
356+
else '')))
357+
358+
def get_cwl_wars(self, war_tag, realtime = None):
359+
return self.request(Route("GET", "/clanwarleagues/wars/{}".format(war_tag) + (
360+
'?realtime=true' if realtime or (not realtime and self.client.realtime)
361+
else '')))
359362

360363
# locations
361364

0 commit comments

Comments
 (0)