all_data.py
14.7 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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
import requests
from urllib import parse
import pymysql
import sys, json
import base64
def select(user_name):
conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll")
check=0
try:
with conn.cursor() as curs:
sql = "select name from user_info"
curs.execute(sql)
rs = curs.fetchall()
for row in rs:
if user_name in row:
check=1
finally:
conn.close()
return check
def read_level(user_name):
conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8')
try:
with conn.cursor() as curs:
sql ="select level from user_info where name=%s"
curs.execute(sql,[user_name,])
for rs in curs.fetchall():
temp=rs[0]
finally:
conn.close()
return temp
def read_tier(user_name):
conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8')
try:
with conn.cursor() as curs:
sql ="select tier from user_info where name=%s"
curs.execute(sql,[user_name,])
for rs in curs.fetchall():
temp=rs[0]
finally:
conn.close()
return temp
def read_score(user_name):
conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8')
try:
with conn.cursor() as curs:
sql ="select opscore from analysis_info where name=%s"
curs.execute(sql,[user_name,])
for rs in curs.fetchall():
temp=rs[0]
finally:
conn.close()
return temp
def read_game(user_name):
conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8')
try:
with conn.cursor() as curs:
curs.execute("select * from game_info where name=%s",[user_name,])
for rs in curs.fetchall():
temp=rs
finally:
conn.close()
lst=list(temp)
return lst[1],lst[2],lst[3],lst[4],lst[5]
def read_kill(user_name):
conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8')
try:
with conn.cursor() as curs:
curs.execute("select kill_cs from game_info where name=%s",[user_name,])
for rs in curs.fetchall():
temp=rs[0]
finally:
conn.close()
return temp
def read_view(user_name):
conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8')
try:
with conn.cursor() as curs:
curs.execute("select view_score from game_info where name=%s",[user_name,])
for rs in curs.fetchall():
temp=rs[0]
finally:
conn.close()
return temp
def read_cs(user_name):
conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8')
try:
with conn.cursor() as curs:
curs.execute("select cs from game_info where name=%s",[user_name,])
for rs in curs.fetchall():
temp=rs[0]
finally:
conn.close()
return temp
def read_as(user_name):
conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8')
try:
with conn.cursor() as curs:
curs.execute("select assist from game_info where name=%s",[user_name,])
for rs in curs.fetchall():
temp=rs[0]
finally:
conn.close()
return temp
def read_death(user_name):
conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8')
try:
with conn.cursor() as curs:
curs.execute("select death from game_info where name=%s",[user_name,])
for rs in curs.fetchall():
temp=rs[0]
finally:
conn.close()
return temp
def read_season(user_name):
conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8')
try:
with conn.cursor() as curs:
curs.execute("select season from match_info where name=%s",[user_name,])
for i in curs.fetchall():
temp=i[0]
break
finally:
conn.close()
return temp
def read_country(user_name):
conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8')
try:
with conn.cursor() as curs:
curs.execute("select country from match_info where name=%s",[user_name,])
for i in curs.fetchall():
temp=i[0]
break
finally:
conn.close()
return temp
def insert_game_table(name, kill,death,ass,cs,view):
if select(name)==1:
conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8')
try:
with conn.cursor() as curs:
sql = 'UPDATE game_info SET kill_cs=%s,death=%s,assist=%s,cs=%s,view_score=%s WHERE name=%s'
curs.execute(sql, (kill,death,ass,cs,view,name))
conn.commit()
finally:
conn.close()
else:
conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8')
try:
with conn.cursor() as curs:
sql = 'insert into game_info values(%s, %s,%s,%s,%s,%s)'
curs.execute(sql, (name, kill,view,cs,death,ass))
conn.commit()
finally:
conn.close()
def insert_match_table(name,country,season):
if select(name)==1:
conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8')
try:
with conn.cursor() as curs:
sql = 'UPDATE match_info SET country=%s,season=%s WHERE name=%s'
curs.execute(sql,(country,season,name))
conn.commit()
finally:
conn.close()
else:
conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8')
try:
with conn.cursor() as curs:
sql = 'insert into match_info values(%s, %s,%s)'
curs.execute(sql, (name, country,season))
conn.commit()
finally:
conn.close()
def insert_score_table(name,score):
if select(name)==1:
conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8')
try:
with conn.cursor() as curs:
sql = 'UPDATE analysis_info SET opscore=%s WHERE name=%s'
curs.execute(sql,(score,name))
conn.commit()
finally:
conn.close()
else:
conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8')
try:
with conn.cursor() as curs:
sql = 'insert into analysis_info values(%s, %s)'
curs.execute(sql, (name, score))
conn.commit()
finally:
conn.close()
def insert_user_table(name,level,tier):
if select(name)==1:
conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8')
try:
with conn.cursor() as curs:
sql = 'UPDATE user_info SET level=%s,tier=%s WHERE name=%s'
curs.execute(sql,(level,tier,name))
conn.commit()
finally:
conn.close()
else:
conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8')
try:
with conn.cursor() as curs:
sql = 'insert into user_info values(%s, %s,%s)'
curs.execute(sql, (name, level,tier))
conn.commit()
finally:
conn.close()
APIKEY = "RGAPI-40d07ed1-81f0-44f1-80c9-c91de5ab20b7"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36",
"Accept-Language": "ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7",
"Accept-Charset": "application/x-www-form-urlencoded; charset=UTF-8",
"Origin": "https://developer.riotgames.com",
"X-Riot-Token": APIKEY
}
def user_level_tier(name):
API="https://kr.api.riotgames.com/lol/summoner/v4/summoners/by-name/" + name
getAPI=requests.get(API, headers=headers)
apidata=getAPI.json()
level=apidata["summonerLevel"]
user_id=apidata["id"]
API="https://kr.api.riotgames.com/lol/league/v4/entries/by-summoner/"+user_id
getAPI=requests.get(API, headers=headers)
apidata=getAPI.json()
#insert_table(name,level,apidata[0]["tier"])
return level,apidata[0]["tier"]
def user_tier(name):
API="https://kr.api.riotgames.com/lol/summoner/v4/summoners/by-name/" + name
getAPI=requests.get(API, headers=headers)
apidata=getAPI.json()
level=apidata["summonerLevel"]
user_id=apidata["id"]
API="https://kr.api.riotgames.com/lol/league/v4/entries/by-summoner/"+user_id
getAPI=requests.get(API, headers=headers)
apidata=getAPI.json()
insert_user_table(name,level,apidata[0]["tier"])
return apidata[0]["tier"]
def game_id(name,num):
API="https://kr.api.riotgames.com/lol/summoner/v4/summoners/by-name/" + name
getAPI=requests.get(API, headers=headers)
LOL_API_DATA=getAPI.json()
accountid=LOL_API_DATA["accountId"]
API="https://kr.api.riotgames.com/lol/match/v4/matchlists/by-account/" + accountid
getAPI=requests.get(API, headers=headers)
LOL_API_DATA=getAPI.json()['matches']
#int값 리턴
return LOL_API_DATA[num].get("gameId")
def season_country(name):
API="https://kr.api.riotgames.com/lol/summoner/v4/summoners/by-name/" + name
getAPI=requests.get(API, headers=headers)
LOL_API_DATA=getAPI.json()
accountid=LOL_API_DATA["accountId"]
API="https://kr.api.riotgames.com/lol/match/v4/matchlists/by-account/" + accountid
getAPI=requests.get(API, headers=headers)
LOL_API_DATA=getAPI.json()['matches']
#str값리턴
insert_match_table(name,LOL_API_DATA[0].get("platformId"),LOL_API_DATA[0].get("season"))
return LOL_API_DATA[0].get("platformId"),LOL_API_DATA[0].get("season")
def opscore(name):
API="https://kr.api.riotgames.com/lol/summoner/v4/summoners/by-name/" + name
getAPI=requests.get(API, headers=headers)
LOL_API_DATA=getAPI.json()
accountid=LOL_API_DATA["accountId"]
API="https://kr.api.riotgames.com/lol/match/v4/matchlists/by-account/" + accountid
getAPI=requests.get(API, headers=headers)
LOL_API_DATA1=getAPI.json()['matches']
kill=0
death=0
ass=0
vision=0
cs=0
time=0
for i in range(0,10):
checkpoint=0
gameid=LOL_API_DATA1[i].get("gameId")
API="https://kr.api.riotgames.com/lol/match/v4/matches/" + str(gameid)
getAPI=requests.get(API, headers=headers)
LOL_API_DATA=getAPI.json()
for j in range(0,10):
if(LOL_API_DATA["participantIdentities"][j]["player"]["summonerName"]==name):
checkpoint=j
j=10
kill=kill+LOL_API_DATA["participants"][checkpoint]["stats"]["kills"]
death=death+LOL_API_DATA["participants"][checkpoint]["stats"]["deaths"]
ass=ass+LOL_API_DATA["participants"][checkpoint]["stats"]["assists"]
cs=cs+LOL_API_DATA["participants"][checkpoint]["stats"]["totalMinionsKilled"]+\
LOL_API_DATA["participants"][checkpoint]["stats"]["neutralMinionsKilled"]
vision=vision+LOL_API_DATA["participants"][checkpoint]["stats"]["visionScore"]
time=time+LOL_API_DATA["gameDuration"]
score=round((kill*3+ass*2)/(death*3),2)+round((cs/(time/60)*0.2),2)+round(vision*0.05,2)
return score
def all_info(name):
API="https://kr.api.riotgames.com/lol/summoner/v4/summoners/by-name/" + name
getAPI=requests.get(API, headers=headers)
LOL_API_DATA=getAPI.json()
accountid=LOL_API_DATA["accountId"]
API="https://kr.api.riotgames.com/lol/match/v4/matchlists/by-account/" + accountid
getAPI=requests.get(API, headers=headers)
LOL_API_DATA1=getAPI.json()['matches']
kill=0
death=0
ass=0
vision=0
cs=0
time=0
for i in range(0,10):
checkpoint=0
gameid=LOL_API_DATA1[i].get("gameId")
API="https://kr.api.riotgames.com/lol/match/v4/matches/" + str(gameid)
getAPI=requests.get(API, headers=headers)
LOL_API_DATA=getAPI.json()
for j in range(0,10):
if(LOL_API_DATA["participantIdentities"][j]["player"]["summonerName"]==name):
checkpoint=j
j=10
kill=kill+LOL_API_DATA["participants"][checkpoint]["stats"]["kills"]
death=death+LOL_API_DATA["participants"][checkpoint]["stats"]["deaths"]
ass=ass+LOL_API_DATA["participants"][checkpoint]["stats"]["assists"]
cs=cs+LOL_API_DATA["participants"][checkpoint]["stats"]["totalMinionsKilled"]+\
LOL_API_DATA["participants"][checkpoint]["stats"]["neutralMinionsKilled"]
vision=vision+LOL_API_DATA["participants"][checkpoint]["stats"]["visionScore"]
time=time+LOL_API_DATA["gameDuration"]
score=round((kill*3+ass*2)/(death*3),2)+round((cs/(time/60)*0.2),2)+round(vision*0.05,2)
insert_game_table(name, round(kill/10,2),round(death/10,2),round(ass/10,2),round(cs/(time/60),2),round(vision/10,2))
insert_score_table(name,score)
a=user_tier(name)
if(a=='BRONZE'):
b=0
if (a == 'SILVER'):
b = 1
if (a == 'GOLD'):
b = 2
if (a == 'PLATINUM'):
b = 3
if (a == 'DIAMOND'):
b = 4
if (a == 'MASTER'):
b = 5
if (a == 'GRANDMASTER'):
b = 6
if (a == 'CHALLENGER'):
b = 7
return [round(kill/10,2),round(death/10,2),round(ass/10,2),round(cs/(time/60),2),round(vision/10,2),score,b]
#Read data from stdin
def read_in():
lines = sys.stdin.readlines()
# Since our input would only be having one line, parse our JSON data from that
return base64.b64decode(lines[0]).decode("UTF-8")
def main():
lines = read_in()
# Sum of all the items in the providen array
user_tier(lines)
season_country(lines)
#return the sum to the output stream
print(all_info(lines))
# Start process
if __name__ == '__main__':
main()
#print(all_info("아이오아이",0))