김선호

최종 CODE

......@@ -2,8 +2,10 @@ 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="password", db="project_troll")
conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll")
check=0
try:
with conn.cursor() as curs:
......@@ -141,16 +143,83 @@ def read_country(user_name):
return temp
def insert_table(name, kill,death,ass,cs,view):
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,death,ass,cs,view))
conn.commit()
finally:
conn.close()
APIKEY = "RGAPI-ddef9646-a6f8-41f6-b54e-7c33dd2989e9"
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",
......@@ -178,7 +247,7 @@ def user_tier(name):
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"])
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
......@@ -199,7 +268,7 @@ def season_country(name):
getAPI=requests.get(API, headers=headers)
LOL_API_DATA=getAPI.json()['matches']
#str값리턴
#insert_table(name,LOL_API_DATA[0].get("platformId"),LOL_API_DATA[0].get("season"))
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
......@@ -237,7 +306,7 @@ def opscore(name):
return score
def all_info(name,c):
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()
......@@ -270,7 +339,8 @@ def all_info(name,c):
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_table(name, round(kill/10,2),round(death/10,2),round(ass/10,2),round(cs/(time/60),2),round(vision/10,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
......@@ -295,24 +365,25 @@ def all_info(name,c):
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,c]
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 json.loads(lines[0])
return base64.b64decode(lines[0]).decode("UTF-8")
def main():
lines = read_in()
c=select(lines)
# 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,c))
print(all_info(lines))
# Start process
if __name__ == '__main__':
main()
#print(all_info("아이오아이",0))
......
var express = require('express');
var router = express.Router();
const { PythonShell } = require('python-shell');
var pyshell = new PythonShell("all_data.py");
......@@ -15,12 +13,14 @@ router.get('/', function(req, res ) {
router.post('/', function(req,res){
console.log(req.body.userid); // req.body.userid를 받아옴
pyshell.send(JSON.stringify(req.body.userid));//the problem function
var pyshell = new PythonShell("all_data.py");
pyshell.send(Buffer.from(req.body.userid).toString('base64'));//the problem function
pyshell.on('message', function (row) {
// received a message sent from the Python script (a simple "print" statement)
console.log(row);
pyshell.kill(9);
return res.render('show', { userid:req.body.userid, data:JSON.parse(row)});
......