김선호

2020-11-14 API연동 및 테스트

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
}
API="https://kr.api.riotgames.com/lol/summoner/v4/summoners/by-name/" + name
getAPI=requests.get(API, headers=headers)
LOL_API_DATA=getAPI.json()
def get_account_id():
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")
No preview for this file type
No preview for this file type
import Get_Account_Id
import Get_Game_Id
import requests
APIKEY=Get_Account_Id.return_key()
name=Get_Account_Id.return_name().replace(" ","").lower()
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()
find_user=-1
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="패배"
print(result)
for j in range(0,10):
game_result(j)