-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleaguebot_version_0.py
50 lines (40 loc) · 1.55 KB
/
leaguebot_version_0.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from riotwatcher import RiotWatcher
from requests import HTTPError
import os
watcher = RiotWatcher(str(os.environ.get("LOL_API_KEY")))
'''
my_region = 'na1'
me = watcher.summoner.by_name(my_region, 'joe joe joe joe')
print(me)
# all objects are returned (by default) as a dict
# lets see if i got diamond yet (i probably didnt)
my_ranked_stats = watcher.league.positions_by_summoner(my_region, me['id'])
print(my_ranked_stats)
'''
def get_summoner_rank(summoner_name, region):
try:
summoner = watcher.summoner.by_name(region, summoner_name)
ranked_stats = watcher.league.positions_by_summoner(region, summoner['id'])
#print(ranked_stats)
if len(ranked_stats) == 0:
return None
ranked_data = []
ranked_data.append(summoner['name'])
for queue in ranked_stats:
if queue['queueType'] == 'RANKED_SOLO_5x5':
ranked_data.append(queue['tier'])
ranked_data.append(queue['rank'])
ranked_data.append(queue['leaguePoints'])
return ranked_data
except HTTPError as err:
if err.response.status_code == 429:
print('We should retry in {} seconds.'.format(e.headers['Retry-After']))
print('this retry-after is handled by default by the RiotWatcher library')
print('future requests wait until the retry-after time passes')
elif err.response.status_code == 404:
print('Summoner with that ridiculous name not found.')
else:
raise
return None
if __name__== "__main__":
print(get_summoner_rank("Ooglyoogly", "na1"))