김선호

Merge branch 'second' into 'master'

Second



See merge request !3
import requests
from urllib import parse
name=parse.quote(input("검색을 원하는 유저 이름을 입력하세요"))
APIKEY="RGAPI-4a16839e-3e5c-4b4e-8b13-1e44b8d621d7"
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 get_account_id():
API="https://kr.api.riotgames.com/lol/summoner/v4/summoners/by-name/" + name
getAPI=requests.get(API, headers=headers)
LOL_API_DATA=getAPI.json()
return LOL_API_DATA["accountId"]
def return_key():
return APIKEY
def return_name():
return name
import Get_Account_Id
import requests
accountid=Get_Account_Id.get_account_id()
APIKEY=Get_Account_Id.return_key()
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
}
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']
def get_game_id(index):
return LOL_API_DATA[index].get("gameId")
def get_champ_id(index):
return LOL_API_DATA[index].get("champion")
# lol_op_rating
#2020-11-15
lol api 연동하여 대용량 데이터를 받아 처리하는 과정을 테스트하였습니다.
유저의 데이터를 대용량으로 가져와 처리하는 과정에서 오픈 API 로 제공하는 rating제한보다
많이 요청하여 오류가 생겼습니다. 해당 문제처리를 위해 DB를 사용하여 CSV파일로 만들어 처리해보겠습니다.
#
#
#2020-11-30
MySQL DB 생성하였습니다.
사용자 UI 디자인 시작하여 중간과정까지 코드 업로드하였습니다.
#
#
#2020-12-01
UI 디자인 완료하였습니다.
import Get_Account_Id
import Get_Game_Id
import requests
APIKEY=Get_Account_Id.return_key()
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 op_score(ac_id):
API="https://kr.api.riotgames.com/lol/match/v4/matchlists/by-account/" + ac_id
getAPI=requests.get(API, headers=headers)
DATA=getAPI.json()["matches"]
score=0
for i in range(0,5):
score+=first_step(DATA[i].get("gameId"),ac_id)
return score
def first_step(gameid,ac_id):
API="https://kr.api.riotgames.com/lol/match/v4/matches/" + str(gameid)
print(gameid)
getAPI=requests.get(API, headers=headers)
f_step_api=getAPI.json()
t_score=0
for i in range(0,10):
if (f_step_api["participantIdentities"][i]["player"]["accountId"]==ac_id):
if f_step_api["participants"][i]["stats"]["deaths"]==0:
t_score=round((f_step_api["participants"][i]["stats"]["kills"]*3+f_step_api["participants"][i]["stats"]["assists"]*0.5)/\
1,2)+round(f_step_api["participants"][i]["stats"]["totalMinionsKilled"]\
/(f_step_api["gameDuration"]/60)*0.2,2)+round(f_step_api["participants"][i]["stats"]["visionScore"]*0.05,2)
else:
t_score=round((f_step_api["participants"][i]["stats"]["kills"]*3+f_step_api["participants"][i]["stats"]["assists"]*0.5)/\
(f_step_api["participants"][i]["stats"]["deaths"]*3),2)+round(f_step_api["participants"][i]["stats"]["totalMinionsKilled"]\
/(f_step_api["gameDuration"]/60)*0.2,2)+round(f_step_api["participants"][i]["stats"]["visionScore"]*0.05,2)
i=10
return t_score
import Get_Account_Id
import Get_Game_Id
import check_score
import requests
APIKEY=Get_Account_Id.return_key()
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 game_result(num):
champid=Get_Game_Id.get_champ_id(num)
gameid=Get_Game_Id.get_game_id(num)
API="https://kr.api.riotgames.com/lol/match/v4/matches/" + str(gameid)
getAPI=requests.get(API, headers=headers)
LOL_API_DATA=getAPI.json()
result=" "
for i in range(0,10):
if LOL_API_DATA["participants"][i]["championId"]==champid:
if LOL_API_DATA["participants"][i]["stats"]["win"]==True:
result="승리"
else:
result="패배"
return result
def match_user_name_and_opscore(num):
gameid=Get_Game_Id.get_game_id(num)
API="https://kr.api.riotgames.com/lol/match/v4/matches/" + str(gameid)
getAPI=requests.get(API, headers=headers)
LOL_API_DATA=getAPI.json()
record_name=[]
record_opscore=[]
for i in range(0,10):
record_name.append(LOL_API_DATA["participantIdentities"][i]["player"]["summonerName"])
print(record_name)
ac_id=LOL_API_DATA["participantIdentities"][i]["player"]["accountId"]
record_opscore.append(check_score.op_score(ac_id))
print(record_opscore)
return record_name,record_opscore
for j in range(0,10):
print(game_result(j))
lst1=[]
lst2=[]
lst1,lst2=match_user_name_and_opscore(j)
print(lst1)
print(lst2)