-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathleagueapi.py
56 lines (43 loc) · 1.59 KB
/
leagueapi.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
import requests
class LolAPI:
"""League API"""
endpoint = 'api.riotgames.com'
def __init__(self, APIKEY: str, region: str):
self.region=region
self.headers={'X-Riot-Token': APIKEY}
def _request(self, path: str) -> requests.models.Response:
res = requests.get(
f'https://{self.region}.{self.endpoint}' + path,
headers=self.headers
)
return res
def getPUUID(self, gameName: str, tagLine: str) -> dict:
"""get ID to make other requets"""
base = f'/riot/account/v1/accounts/by-riot-id/'
res = self._request(base + f'{gameName}/{tagLine}')
return res.json()['puuid']
def getMatchIdList(self, puuid: str, n: int=20) -> list:
"""get list of n most recent match by match id
Notes
-----
API response returns at most 100 IDs per call
Matches are kept for 2 years
"""
base = f'/lol/match/v5/matches/by-puuid/{puuid}/ids/?'
match_ids = []
start = 0
while n > 0:
count = min(n, 100)
res = self._request(base + f'start={start}&count={count}')
match_ids += res.json()
if len(res.json()) == 0:
break
start += 100
n -= 100
return match_ids
def getMatchInfo(self, match_id: str) -> dict:
res = self._request(f'/lol/match/v5/matches/{match_id}')
return res.json()
def getMatchTimeline(self, match_id: str) -> dict:
res = self._request(f'/lol/match/v5/matches/{match_id}/timeline')
return res.json()