-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRIOTAPI.py
64 lines (49 loc) · 1.53 KB
/
RIOTAPI.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from enum import Enum
import requests
from RateLimit import RateLimit
class Server(Enum):
NA = "na1"
BR = "br1"
LAN = "la1"
LAS = "la2"
OCE = "oc1"
KR = "kr"
JP = "jp1"
EUNE = "eun1"
EUW = "euw1"
TR = "tr1"
RU = "ru"
class MajorRegion(Enum):
AMERICAS = "americas"
ASIA = "asia"
EUROPE = "europe"
class QueueType(Enum):
Draft5x5 = 400
Ranked5x5 = 420
Blind5x5 = 430
Flex5x5 = 440
ARAM = 450
CLASH = 700
class RIOTAPI:
def __init__(self, apikey : str):
self.key = apikey
self.secondRateLimit = RateLimit(20, 1, 0.1, .1)
self.minuteRateLimit = RateLimit(100, 120, 0.1, 10)
def request(self, server : Server, endpoint : str):
headers = {"X-Riot-Token": self.key}
url = "https://{}.api.riotgames.com{}".format(server.value, endpoint)
# Wait for the second rate limit
self.secondRateLimit.waitForRateLimit()
# Wair for the minute rate limit
self.minuteRateLimit.waitForRateLimit()
r = requests.get(url, headers=headers)
return r.json()
def requestMajorRegion(self, region : MajorRegion, endpoint : str):
headers = {"X-Riot-Token": self.key}
url = "https://{}.api.riotgames.com{}".format(region.value, endpoint)
# Wait for the second rate limit
self.secondRateLimit.waitForRateLimit()
# Wair for the minute rate limit
self.minuteRateLimit.waitForRateLimit()
r = requests.get(url, headers=headers)
return r.json()