From 340227db5fe260f5304e02cc09ff27641295a320 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 13 Aug 2016 15:56:27 +0200 Subject: [PATCH] Rate limits handling part2 --- league.py | 5 +++++ main.py | 3 +++ 2 files changed, 8 insertions(+) diff --git a/league.py b/league.py index 0a3b8563..39718b40 100644 --- a/league.py +++ b/league.py @@ -10,6 +10,9 @@ class NoRankedGamesCompletedException(Exception): pass +class RateLimitException(Exception): + pass + loop = asyncio.get_event_loop() # Load League of Legends API key from the leaguetoken.txt file @@ -33,5 +36,7 @@ async def get_player_rank(region: str, summonerid: int, **kwargs): return r.json()[str(summonerid)][0] elif r.status_code == 404: raise NoRankedGamesCompletedException("This player hasn't completed any ranked games.") + elif r.status_code == 429: + raise RateLimitException("You've been ratelimited by Riot. Check your developer dashboard.") else: raise Exception("Unhandled API response.") diff --git a/main.py b/main.py index 82f4302c..e1409587 100644 --- a/main.py +++ b/main.py @@ -69,6 +69,9 @@ async def league_rank_change(timeout): except league.NoRankedGamesCompletedException: # If the player has no ranked games completed, skip him continue + except league.RateLimitException: + # If you've been ratelimited, skip the player and notify the console. + print("[League] Request rejected for rate limit.") else: # Convert tier into a number tier_number = league.ranklist.index(r["tier"])