-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcu.py
74 lines (53 loc) · 1.87 KB
/
lcu.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
65
66
67
68
69
70
71
72
73
74
import base64
import json
import os
import requests
import utils
class LCU:
def __init__(self, token, port):
self.token = token
self.port = port
self.headers = self._build_headers()
self.url = f"https://127.0.0.1:{port}"
os.mkdir("./runes") if not os.path.exists("runes") else ""
def _build_headers(self):
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization": "Basic " + base64.b64encode(("riot:" + self.token).encode("UTF-8")).decode("UTF-8")
}
return headers
def get_runes(self):
"""
获取符文页
"""
url = self.url + "/lol-perks/v1/pages"
resp = requests.get(url, headers=self.headers, verify=False)
if not resp.ok:
utils.error("获取符文页失败!")
return
resp_content = resp.text
runes = []
for item in json.loads(resp_content):
if item['isDeletable']:
runes.append(item)
return runes
def delete_one_runes(self, runes, index=0):
if len(runes) <= 1:
return
url = self.url + "/lol-perks/v1/pages/" + str(runes[index]['id'])
resp = requests.delete(url, headers=self.headers, verify=False)
if not resp.ok:
utils.error("删除符文失败!")
return
def load_rune(self, rune_filename):
filepath = './runes/' + rune_filename
with open(filepath, encoding='utf-8') as f:
rune = f.read()
url = self.url + "/lol-perks/v1/pages"
rune_json = json.loads(rune)
rune_json['name'] = rune_filename[:-5]
resp = requests.post(url, json=rune_json, headers=self.headers, verify=False)
if not resp.ok:
utils.error("载入符文页失败!")
return