@@ -166,18 +166,18 @@ class HTTPClient:
166166
167167 # pylint: disable=too-many-arguments, missing-docstring, protected-access, too-many-branches
168168 def __init__ (
169- self ,
170- client ,
171- loop ,
172- email ,
173- password ,
174- key_names ,
175- key_count ,
176- key_scopes ,
177- throttle_limit ,
178- throttler = BasicThrottler ,
179- cache_max_size = 10000 ,
180- stats_max_size = 1000 ,
169+ self ,
170+ client ,
171+ loop ,
172+ email ,
173+ password ,
174+ key_names ,
175+ key_count ,
176+ key_scopes ,
177+ throttle_limit ,
178+ throttler = BasicThrottler ,
179+ cache_max_size = 10000 ,
180+ stats_max_size = 1000
181181 ):
182182 self .client = client
183183 self .loop = loop
@@ -187,7 +187,6 @@ def __init__(
187187 self .key_count = key_count
188188 self .key_scopes = key_scopes
189189 self .throttle_limit = throttle_limit
190-
191190 per_second = key_count * throttle_limit
192191
193192 self .__session = None
@@ -226,7 +225,7 @@ async def request(self, route, **kwargs):
226225 url = route .url
227226
228227 headers = {
229- "Accept" : "application/json" ,
228+ "Accept" : "application/json" ,
230229 "authorization" : "Bearer {}" .format (next (self .keys )),
231230 }
232231 kwargs ["headers" ] = headers
@@ -237,7 +236,7 @@ async def request(self, route, **kwargs):
237236 cache_control_key = route .url
238237 cache = self .cache
239238 # the cache will be cleaned once it becomes stale / a new object is available from the api.
240- if cache is not None :
239+ if cache is not None and not self . client . realtime :
241240 try :
242241 return cache [cache_control_key ]
243242 except KeyError :
@@ -261,7 +260,7 @@ async def request(self, route, **kwargs):
261260 # set a callback to remove the item from cache once it's stale.
262261 delta = int (response .headers ["Cache-Control" ].strip ("max-age=" ))
263262 data ["_response_retry" ] = delta
264- if cache is not None :
263+ if cache is not None and not self . client . realtime :
265264 self .cache [cache_control_key ] = data
266265 LOG .debug ("Cache-Control max age: %s seconds, key: %s" , delta , cache_control_key )
267266 self .loop .call_later (delta , self ._cache_remove , cache_control_key )
@@ -294,8 +293,8 @@ async def request(self, route, **kwargs):
294293 raise NotFound (response , data )
295294 if response .status == 429 :
296295 LOG .error (
297- "We have been rate-limited by the API. "
298- "Reconsider the number of requests you are allowing per second."
296+ "We have been rate-limited by the API. "
297+ "Reconsider the number of requests you are allowing per second."
299298 )
300299 raise HTTPException (response , data )
301300
@@ -346,14 +345,20 @@ def get_clan_members(self, tag):
346345 def get_clan_warlog (self , tag ):
347346 return self .request (Route ("GET" , "/clans/{}/warlog" .format (tag )))
348347
349- def get_clan_current_war (self , tag ):
350- return self .request (Route ("GET" , "/clans/{}/currentwar" .format (tag )))
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 (realtime is None and self .client .realtime )
351+ else '' )))
351352
352- def get_clan_war_league_group (self , tag ):
353- return self .request (Route ("GET" , "/clans/{}/currentwar/leaguegroup" .format (tag )))
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 (realtime is None and self .client .realtime )
356+ else '' )))
354357
355- def get_cwl_wars (self , war_tag ):
356- return self .request (Route ("GET" , "/clanwarleagues/wars/{}" .format (war_tag )))
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 (realtime is None and self .client .realtime )
361+ else '' )))
357362
358363 # locations
359364
@@ -433,17 +438,17 @@ async def initialise_keys(self):
433438 if len (self ._keys ) < self .key_count :
434439 for key in (k for k in keys if k ["name" ] == self .key_names and ip not in k ["cidrRanges" ]):
435440 LOG .info (
436- "Deleting key with the name %s and IP %s (not matching our current IP address)." ,
437- self .key_names , key ["cidrRanges" ],
441+ "Deleting key with the name %s and IP %s (not matching our current IP address)." ,
442+ self .key_names , key ["cidrRanges" ],
438443 )
439444 await session .post ("https://developer.clashofclans.com/api/apikey/revoke" , json = {"id" : key ["id" ]})
440445
441446 while len (self ._keys ) < self .key_count and len (keys ) < KEY_MAXIMUM :
442447 data = {
443- "name" : self .key_names ,
448+ "name" : self .key_names ,
444449 "description" : "Created on {}" .format (datetime .now ().strftime ("%c" )),
445- "cidrRanges" : [ip ],
446- "scopes" : [self .key_scopes ],
450+ "cidrRanges" : [ip ],
451+ "scopes" : [self .key_scopes ],
447452 }
448453
449454 LOG .info ("Creating key with data %s." , str (data ))
@@ -462,9 +467,9 @@ async def initialise_keys(self):
462467 if len (self ._keys ) == 0 :
463468 await self .close ()
464469 raise RuntimeError (
465- "There are {} API keys already created and none match a key_name of '{}'."
466- "Please specify a key_name kwarg, or go to 'https://developer.clashofclans.com' to delete "
467- "unused keys." .format (len (keys ), self .key_names )
470+ "There are {} API keys already created and none match a key_name of '{}'."
471+ "Please specify a key_name kwarg, or go to 'https://developer.clashofclans.com' to delete "
472+ "unused keys." .format (len (keys ), self .key_names )
468473 )
469474
470475 await session .close ()
0 commit comments