1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00

Rate limits handling part2

This commit is contained in:
Steffo 2016-08-13 15:56:27 +02:00
parent d36f552fc2
commit 340227db5f
2 changed files with 8 additions and 0 deletions

View file

@ -10,6 +10,9 @@ class NoRankedGamesCompletedException(Exception):
pass pass
class RateLimitException(Exception):
pass
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
# Load League of Legends API key from the leaguetoken.txt file # 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] return r.json()[str(summonerid)][0]
elif r.status_code == 404: elif r.status_code == 404:
raise NoRankedGamesCompletedException("This player hasn't completed any ranked games.") 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: else:
raise Exception("Unhandled API response.") raise Exception("Unhandled API response.")

View file

@ -69,6 +69,9 @@ async def league_rank_change(timeout):
except league.NoRankedGamesCompletedException: except league.NoRankedGamesCompletedException:
# If the player has no ranked games completed, skip him # If the player has no ranked games completed, skip him
continue continue
except league.RateLimitException:
# If you've been ratelimited, skip the player and notify the console.
print("[League] Request rejected for rate limit.")
else: else:
# Convert tier into a number # Convert tier into a number
tier_number = league.ranklist.index(r["tier"]) tier_number = league.ranklist.index(r["tier"])