Showing
2 changed files
with
94 additions
and
23 deletions
... | @@ -2,8 +2,10 @@ import requests | ... | @@ -2,8 +2,10 @@ import requests |
2 | from urllib import parse | 2 | from urllib import parse |
3 | import pymysql | 3 | import pymysql |
4 | import sys, json | 4 | import sys, json |
5 | +import base64 | ||
6 | + | ||
5 | def select(user_name): | 7 | def select(user_name): |
6 | - conn = pymysql.connect(host='localhost', user='root', password="password", db="project_troll") | 8 | + conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll") |
7 | check=0 | 9 | check=0 |
8 | try: | 10 | try: |
9 | with conn.cursor() as curs: | 11 | with conn.cursor() as curs: |
... | @@ -141,16 +143,83 @@ def read_country(user_name): | ... | @@ -141,16 +143,83 @@ def read_country(user_name): |
141 | return temp | 143 | return temp |
142 | 144 | ||
143 | 145 | ||
144 | -def insert_table(name, kill,death,ass,cs,view): | 146 | +def insert_game_table(name, kill,death,ass,cs,view): |
145 | - conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8') | 147 | + if select(name)==1: |
146 | - try: | 148 | + conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8') |
147 | - with conn.cursor() as curs: | 149 | + try: |
148 | - sql = 'insert into game_info values(%s, %s,%s,%s,%s,%s)' | 150 | + with conn.cursor() as curs: |
149 | - curs.execute(sql, (name, kill,death,ass,cs,view)) | 151 | + sql = 'UPDATE game_info SET kill_cs=%s,death=%s,assist=%s,cs=%s,view_score=%s WHERE name=%s' |
150 | - conn.commit() | 152 | + curs.execute(sql, (kill,death,ass,cs,view,name)) |
151 | - finally: | 153 | + conn.commit() |
152 | - conn.close() | 154 | + finally: |
153 | -APIKEY = "RGAPI-ddef9646-a6f8-41f6-b54e-7c33dd2989e9" | 155 | + conn.close() |
156 | + else: | ||
157 | + conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8') | ||
158 | + try: | ||
159 | + with conn.cursor() as curs: | ||
160 | + sql = 'insert into game_info values(%s, %s,%s,%s,%s,%s)' | ||
161 | + curs.execute(sql, (name, kill,view,cs,death,ass)) | ||
162 | + conn.commit() | ||
163 | + finally: | ||
164 | + conn.close() | ||
165 | +def insert_match_table(name,country,season): | ||
166 | + if select(name)==1: | ||
167 | + conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8') | ||
168 | + try: | ||
169 | + with conn.cursor() as curs: | ||
170 | + sql = 'UPDATE match_info SET country=%s,season=%s WHERE name=%s' | ||
171 | + curs.execute(sql,(country,season,name)) | ||
172 | + conn.commit() | ||
173 | + finally: | ||
174 | + conn.close() | ||
175 | + else: | ||
176 | + conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8') | ||
177 | + try: | ||
178 | + with conn.cursor() as curs: | ||
179 | + sql = 'insert into match_info values(%s, %s,%s)' | ||
180 | + curs.execute(sql, (name, country,season)) | ||
181 | + conn.commit() | ||
182 | + finally: | ||
183 | + conn.close() | ||
184 | +def insert_score_table(name,score): | ||
185 | + if select(name)==1: | ||
186 | + conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8') | ||
187 | + try: | ||
188 | + with conn.cursor() as curs: | ||
189 | + sql = 'UPDATE analysis_info SET opscore=%s WHERE name=%s' | ||
190 | + curs.execute(sql,(score,name)) | ||
191 | + conn.commit() | ||
192 | + finally: | ||
193 | + conn.close() | ||
194 | + else: | ||
195 | + conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8') | ||
196 | + try: | ||
197 | + with conn.cursor() as curs: | ||
198 | + sql = 'insert into analysis_info values(%s, %s)' | ||
199 | + curs.execute(sql, (name, score)) | ||
200 | + conn.commit() | ||
201 | + finally: | ||
202 | + conn.close() | ||
203 | +def insert_user_table(name,level,tier): | ||
204 | + if select(name)==1: | ||
205 | + conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8') | ||
206 | + try: | ||
207 | + with conn.cursor() as curs: | ||
208 | + sql = 'UPDATE user_info SET level=%s,tier=%s WHERE name=%s' | ||
209 | + curs.execute(sql,(level,tier,name)) | ||
210 | + conn.commit() | ||
211 | + finally: | ||
212 | + conn.close() | ||
213 | + else: | ||
214 | + conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8') | ||
215 | + try: | ||
216 | + with conn.cursor() as curs: | ||
217 | + sql = 'insert into user_info values(%s, %s,%s)' | ||
218 | + curs.execute(sql, (name, level,tier)) | ||
219 | + conn.commit() | ||
220 | + finally: | ||
221 | + conn.close() | ||
222 | +APIKEY = "RGAPI-40d07ed1-81f0-44f1-80c9-c91de5ab20b7" | ||
154 | headers = { | 223 | headers = { |
155 | "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", | 224 | "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", |
156 | "Accept-Language": "ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7", | 225 | "Accept-Language": "ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7", |
... | @@ -178,7 +247,7 @@ def user_tier(name): | ... | @@ -178,7 +247,7 @@ def user_tier(name): |
178 | API="https://kr.api.riotgames.com/lol/league/v4/entries/by-summoner/"+user_id | 247 | API="https://kr.api.riotgames.com/lol/league/v4/entries/by-summoner/"+user_id |
179 | getAPI=requests.get(API, headers=headers) | 248 | getAPI=requests.get(API, headers=headers) |
180 | apidata=getAPI.json() | 249 | apidata=getAPI.json() |
181 | - #insert_table(name,level,apidata[0]["tier"]) | 250 | + insert_user_table(name,level,apidata[0]["tier"]) |
182 | return apidata[0]["tier"] | 251 | return apidata[0]["tier"] |
183 | def game_id(name,num): | 252 | def game_id(name,num): |
184 | API="https://kr.api.riotgames.com/lol/summoner/v4/summoners/by-name/" + name | 253 | API="https://kr.api.riotgames.com/lol/summoner/v4/summoners/by-name/" + name |
... | @@ -199,7 +268,7 @@ def season_country(name): | ... | @@ -199,7 +268,7 @@ def season_country(name): |
199 | getAPI=requests.get(API, headers=headers) | 268 | getAPI=requests.get(API, headers=headers) |
200 | LOL_API_DATA=getAPI.json()['matches'] | 269 | LOL_API_DATA=getAPI.json()['matches'] |
201 | #str값리턴 | 270 | #str값리턴 |
202 | - #insert_table(name,LOL_API_DATA[0].get("platformId"),LOL_API_DATA[0].get("season")) | 271 | + insert_match_table(name,LOL_API_DATA[0].get("platformId"),LOL_API_DATA[0].get("season")) |
203 | return LOL_API_DATA[0].get("platformId"),LOL_API_DATA[0].get("season") | 272 | return LOL_API_DATA[0].get("platformId"),LOL_API_DATA[0].get("season") |
204 | def opscore(name): | 273 | def opscore(name): |
205 | API="https://kr.api.riotgames.com/lol/summoner/v4/summoners/by-name/" + name | 274 | API="https://kr.api.riotgames.com/lol/summoner/v4/summoners/by-name/" + name |
... | @@ -237,7 +306,7 @@ def opscore(name): | ... | @@ -237,7 +306,7 @@ def opscore(name): |
237 | return score | 306 | return score |
238 | 307 | ||
239 | 308 | ||
240 | -def all_info(name,c): | 309 | +def all_info(name): |
241 | API="https://kr.api.riotgames.com/lol/summoner/v4/summoners/by-name/" + name | 310 | API="https://kr.api.riotgames.com/lol/summoner/v4/summoners/by-name/" + name |
242 | getAPI=requests.get(API, headers=headers) | 311 | getAPI=requests.get(API, headers=headers) |
243 | LOL_API_DATA=getAPI.json() | 312 | LOL_API_DATA=getAPI.json() |
... | @@ -270,7 +339,8 @@ def all_info(name,c): | ... | @@ -270,7 +339,8 @@ def all_info(name,c): |
270 | vision=vision+LOL_API_DATA["participants"][checkpoint]["stats"]["visionScore"] | 339 | vision=vision+LOL_API_DATA["participants"][checkpoint]["stats"]["visionScore"] |
271 | time=time+LOL_API_DATA["gameDuration"] | 340 | time=time+LOL_API_DATA["gameDuration"] |
272 | score=round((kill*3+ass*2)/(death*3),2)+round((cs/(time/60)*0.2),2)+round(vision*0.05,2) | 341 | score=round((kill*3+ass*2)/(death*3),2)+round((cs/(time/60)*0.2),2)+round(vision*0.05,2) |
273 | - #insert_table(name, round(kill/10,2),round(death/10,2),round(ass/10,2),round(cs/(time/60),2),round(vision/10,2)) | 342 | + 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)) |
343 | + insert_score_table(name,score) | ||
274 | a=user_tier(name) | 344 | a=user_tier(name) |
275 | if(a=='BRONZE'): | 345 | if(a=='BRONZE'): |
276 | b=0 | 346 | b=0 |
... | @@ -295,24 +365,25 @@ def all_info(name,c): | ... | @@ -295,24 +365,25 @@ def all_info(name,c): |
295 | if (a == 'CHALLENGER'): | 365 | if (a == 'CHALLENGER'): |
296 | b = 7 | 366 | b = 7 |
297 | 367 | ||
298 | - return [round(kill/10,2),round(death/10,2),round(ass/10,2),round(cs/(time/60),2),round(vision/10,2),score,b,c] | 368 | + return [round(kill/10,2),round(death/10,2),round(ass/10,2),round(cs/(time/60),2),round(vision/10,2),score,b] |
299 | 369 | ||
300 | #Read data from stdin | 370 | #Read data from stdin |
301 | def read_in(): | 371 | def read_in(): |
302 | lines = sys.stdin.readlines() | 372 | lines = sys.stdin.readlines() |
303 | # Since our input would only be having one line, parse our JSON data from that | 373 | # Since our input would only be having one line, parse our JSON data from that |
304 | - return json.loads(lines[0]) | 374 | + return base64.b64decode(lines[0]).decode("UTF-8") |
305 | 375 | ||
306 | def main(): | 376 | def main(): |
307 | 377 | ||
308 | lines = read_in() | 378 | lines = read_in() |
309 | - c=select(lines) | ||
310 | # Sum of all the items in the providen array | 379 | # Sum of all the items in the providen array |
311 | - | 380 | + user_tier(lines) |
381 | + season_country(lines) | ||
312 | #return the sum to the output stream | 382 | #return the sum to the output stream |
313 | - print(all_info(lines,c)) | 383 | + print(all_info(lines)) |
314 | 384 | ||
315 | # Start process | 385 | # Start process |
316 | if __name__ == '__main__': | 386 | if __name__ == '__main__': |
317 | main() | 387 | main() |
318 | 388 | ||
389 | +#print(all_info("아이오아이",0)) | ... | ... |
1 | var express = require('express'); | 1 | var express = require('express'); |
2 | var router = express.Router(); | 2 | var router = express.Router(); |
3 | const { PythonShell } = require('python-shell'); | 3 | const { PythonShell } = require('python-shell'); |
4 | -var pyshell = new PythonShell("all_data.py"); | ||
5 | - | ||
6 | 4 | ||
7 | 5 | ||
8 | 6 | ||
... | @@ -15,12 +13,14 @@ router.get('/', function(req, res ) { | ... | @@ -15,12 +13,14 @@ router.get('/', function(req, res ) { |
15 | router.post('/', function(req,res){ | 13 | router.post('/', function(req,res){ |
16 | console.log(req.body.userid); // req.body.userid를 받아옴 | 14 | console.log(req.body.userid); // req.body.userid를 받아옴 |
17 | 15 | ||
18 | - pyshell.send(JSON.stringify(req.body.userid));//the problem function | 16 | + var pyshell = new PythonShell("all_data.py"); |
17 | + pyshell.send(Buffer.from(req.body.userid).toString('base64'));//the problem function | ||
19 | 18 | ||
20 | pyshell.on('message', function (row) { | 19 | pyshell.on('message', function (row) { |
21 | // received a message sent from the Python script (a simple "print" statement) | 20 | // received a message sent from the Python script (a simple "print" statement) |
22 | 21 | ||
23 | console.log(row); | 22 | console.log(row); |
23 | + pyshell.kill(9); | ||
24 | return res.render('show', { userid:req.body.userid, data:JSON.parse(row)}); | 24 | return res.render('show', { userid:req.body.userid, data:JSON.parse(row)}); |
25 | 25 | ||
26 | 26 | ... | ... |
-
Please register or login to post a comment