-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstatic-database.py
149 lines (145 loc) · 4.75 KB
/
static-database.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import urllib3
import certifi
import json
import sqlite3
import traceback
# Init
http = urllib3.PoolManager(
cert_reqs='CERT_REQUIRED',
ca_certs=certifi.where(),
)
conn = sqlite3.connect('database.db')
c = conn.cursor()
with open('apikey.txt', 'r') as f:
apiKey = f.read()
# Champions
try:
c.execute('''CREATE TABLE champion (
version TEXT,
id INTEGER,
name TEXT,
title TEXT,
PRIMARY KEY (version, id))
''')
except:
traceback.print_exc()
try:
# Items
c.execute(
'''CREATE TABLE item (
version TEXT,
id INTEGER,
name TEXT,
flatAp INTEGER,
percentAp REAL,
gold INTEGER,
PRIMARY KEY (version, id)
)''')
c.execute('''CREATE INDEX [item-version-id] ON item (
version,
id
);''')
except:
traceback.print_exc()
try:
# Runes
c.execute(
'''CREATE TABLE rune (
id INTEGER,
name TEXT,
version TEXT,
flatAp INTEGER,
percentAp REAL,
PRIMARY KEY (version, id)
)''')
except:
traceback.print_exc()
try:
# Masteries
c.execute(
'''CREATE TABLE mastery (
id INTEGER,
name TEXT,
version TEXT,
rank INTEGER,
flatAp INTEGER,
percentAp REAL,
PRIMARY KEY (version, id, rank)
)''')
except:
traceback.print_exc()
def populateStaticTables(version):
print('Version ' + version + ' static tables')
# Champions
try:
r = http.request(
'GET', 'https://global.api.pvp.net/api/lol/static-data/na/v1.2/champion?version={}&api_key={}'.format(version, apiKey))
if r.status != 200:
print('HTTP request failed:' + str(r.status))
raise Exception
responseData = json.loads(r.data.decode("utf-8"))
for championKey, champion in responseData["data"].items():
c.execute('''INSERT INTO champion (version, id, name, title) VALUES (?, ?, ?, ?)''',
(version[:4], champion['id'], champion['name'], champion['title']))
print("Champions table created with {} champions.".format(
len(responseData["data"])))
except Exception:
traceback.print_exc()
# Items
try:
r = http.request(
'GET', 'https://global.api.pvp.net/api/lol/static-data/na/v1.2/item?version={}&itemListData=gold,image,stats&api_key={}'.format(version, apiKey))
if r.status != 200:
print('HTTP request failed:' + str(r.status))
raise Exception
responseData = json.loads(r.data.decode("utf-8"))
for itemId, item in responseData["data"].items():
c.execute('''INSERT INTO item (id, name, version, flatAp, percentAp, gold) VALUES (?, ?, ?, ?, ?, ?)''',
(item["id"], item["name"], version[:4], item["stats"].get("FlatMagicDamageMod", 0),
item["stats"].get("PercentMagicDamageMod", 0), item["gold"]["total"]))
# Deathcap pls
c.execute('''UPDATE item SET percentAp = 30 WHERE id = 3089''')
print("Items table created with {} items.".format(
len(responseData["data"])))
except Exception:
traceback.print_exc()
# Runes
try:
r = http.request(
'GET', 'https://global.api.pvp.net/api/lol/static-data/na/v1.2/rune?version={}&runeListData=stats&api_key={}'.format(version, apiKey))
if r.status != 200:
print('HTTP request failed:' + str(r.status))
raise Exception
responseData = json.loads(r.data.decode("utf-8"))
for runeId, rune in responseData["data"].items():
c.execute('INSERT INTO rune (id, name, version, flatAp, percentAp) VALUES (?, ?, ?, ?, ?)', (rune["id"], rune[
"name"], version[:4], rune["stats"].get("FlatMagicDamageMod", 0), rune["stats"].get("PercentMagicDamageMod", 0)))
print("Runes table created with {} runes.".format(len(responseData["data"])))
except Exception:
traceback.print_exc()
# Masteries
try:
c.execute('INSERT INTO mastery (id, name, version, rank, flatAp, percentAp) VALUES (?, ?, ?, ?, ?, ?)',
(4123, 'Mental Force', version[:4], 1, 6, 0))
c.execute('INSERT INTO mastery (id, name, version, rank, flatAp, percentAp) VALUES (?, ?, ?, ?, ?, ?)',
(4123, 'Mental Force', version[:4], 2, 11, 0))
c.execute('INSERT INTO mastery (id, name, version, rank, flatAp, percentAp) VALUES (?, ?, ?, ?, ?, ?)',
(4123, 'Mental Force', version[:4], 3, 16, 0))
c.execute('INSERT INTO mastery (id, name, version, rank, flatAp, percentAp) VALUES (?, ?, ?, ?, ?, ?)',
(4133, 'Arcane Mastery', version[:4], 1, 6, 0))
c.execute('INSERT INTO mastery (id, name, version, rank, flatAp, percentAp) VALUES (?, ?, ?, ?, ?, ?)',
(4143, 'Archmage', version[:4], 1, 0, 2))
c.execute('INSERT INTO mastery (id, name, version, rank, flatAp, percentAp) VALUES (?, ?, ?, ?, ?, ?)',
(4143, 'Archmage', version[:4], 2, 0, 3.5))
c.execute('INSERT INTO mastery (id, name, version, rank, flatAp, percentAp) VALUES (?, ?, ?, ?, ?, ?)',
(4143, 'Archmage', version[:4], 3, 0, 5))
print("Masteries table created with {} masteries.".format(7))
except Exception:
traceback.print_exc()
populateStaticTables('5.11.1')
populateStaticTables('5.14.1')
conn.commit()
# Finalize
conn.close()
print('Done!')
input()