mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Rate limits handling part2
This commit is contained in:
parent
d36f552fc2
commit
340227db5f
2 changed files with 8 additions and 0 deletions
|
@ -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.")
|
||||
|
|
3
main.py
3
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"])
|
||||
|
|
Loading…
Reference in a new issue