This repository was archived by the owner on Nov 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
56 lines (49 loc) · 1.9 KB
/
api.py
File metadata and controls
56 lines (49 loc) · 1.9 KB
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 base64
import psutil
import os
import requests
from urllib3 import disable_warnings
disable_warnings()
def get_process_by_name(process_name):
while True:
for proc in psutil.process_iter():
try:
if process_name in proc.name():
return proc
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass
class LeagueClientAPI(object):
def __init__(self):
print('Waiting for League client...')
self.process = get_process_by_name("LeagueClientUx")
self.lockfile = open(os.path.join(self.process.cwd(), "lockfile"), 'r').read()
split = self.lockfile.split(":")
self.process_name = split[0]
self.process_id = split[1]
self.port = split[2]
self.password = str(base64.b64encode(("riot:" + split[3]).encode("utf-8")), "utf-8")
self.protocol = split[4]
self.access_token = requests.get(
self.protocol + "://127.0.0.1:" + self.port + "/lol-rso-auth/v1/authorization/access-token",
verify=False,
headers={"Authorization": "Basic " + self.password}).json()
def get(self, path):
return requests.get(
self.protocol + "://127.0.0.1:" + self.port + path,
verify=False,
headers={"Authorization": "Basic " + self.password}
)
def get_token(self, path):
token = self.access_token["token"]
return requests.get("https://" + "vn2-red.lol.sgp.pvp.net" + path,
verify=False,
headers={"Authorization": "Bearer " + token}
)
def postRefund(self, path, json=None):
token = self.access_token["token"]
return requests.post(
self.protocol + "://" + "vn2-red.lol.sgp.pvp.net" + path,
verify=False,
headers={"Authorization": "Bearer " + token},
json=json
)