김선호

Merge branch 'second' into 'master'

Second



See merge request !3
1 +import requests
2 +from urllib import parse
3 +name=parse.quote(input("검색을 원하는 유저 이름을 입력하세요"))
4 +APIKEY="RGAPI-4a16839e-3e5c-4b4e-8b13-1e44b8d621d7"
5 +headers={
6 + "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",
7 + "Accept-Language": "ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7",
8 + "Accept-Charset": "application/x-www-form-urlencoded; charset=UTF-8",
9 + "Origin": "https://developer.riotgames.com",
10 + "X-Riot-Token": APIKEY
11 + }
12 +def get_account_id():
13 + API="https://kr.api.riotgames.com/lol/summoner/v4/summoners/by-name/" + name
14 + getAPI=requests.get(API, headers=headers)
15 + LOL_API_DATA=getAPI.json()
16 + return LOL_API_DATA["accountId"]
17 +def return_key():
18 + return APIKEY
19 +def return_name():
20 + return name
21 +
22 +
1 +import Get_Account_Id
2 +import requests
3 +accountid=Get_Account_Id.get_account_id()
4 +APIKEY=Get_Account_Id.return_key()
5 +headers = {
6 + "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",
7 + "Accept-Language": "ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7",
8 + "Accept-Charset": "application/x-www-form-urlencoded; charset=UTF-8",
9 + "Origin": "https://developer.riotgames.com",
10 + "X-Riot-Token": APIKEY
11 + }
12 +API="https://kr.api.riotgames.com/lol/match/v4/matchlists/by-account/" + accountid
13 +getAPI=requests.get(API, headers=headers)
14 +LOL_API_DATA=getAPI.json()['matches']
15 +def get_game_id(index):
16 + return LOL_API_DATA[index].get("gameId")
17 +def get_champ_id(index):
18 + return LOL_API_DATA[index].get("champion")
19 +
1 +# lol_op_rating
2 +#2020-11-15
3 +lol api 연동하여 대용량 데이터를 받아 처리하는 과정을 테스트하였습니다.
4 +유저의 데이터를 대용량으로 가져와 처리하는 과정에서 오픈 API 로 제공하는 rating제한보다
5 +많이 요청하여 오류가 생겼습니다. 해당 문제처리를 위해 DB를 사용하여 CSV파일로 만들어 처리해보겠습니다.
6 +#
7 +#
8 +#2020-11-30
9 +MySQL DB 생성하였습니다.
10 +사용자 UI 디자인 시작하여 중간과정까지 코드 업로드하였습니다.
11 +#
12 +#
13 +#2020-12-01
14 +UI 디자인 완료하였습니다.
1 +import Get_Account_Id
2 +import Get_Game_Id
3 +import requests
4 +APIKEY=Get_Account_Id.return_key()
5 +headers = {
6 + "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",
7 + "Accept-Language": "ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7",
8 + "Accept-Charset": "application/x-www-form-urlencoded; charset=UTF-8",
9 + "Origin": "https://developer.riotgames.com",
10 + "X-Riot-Token": APIKEY
11 + }
12 +def op_score(ac_id):
13 + API="https://kr.api.riotgames.com/lol/match/v4/matchlists/by-account/" + ac_id
14 + getAPI=requests.get(API, headers=headers)
15 + DATA=getAPI.json()["matches"]
16 + score=0
17 + for i in range(0,5):
18 + score+=first_step(DATA[i].get("gameId"),ac_id)
19 + return score
20 +
21 +def first_step(gameid,ac_id):
22 + API="https://kr.api.riotgames.com/lol/match/v4/matches/" + str(gameid)
23 + print(gameid)
24 + getAPI=requests.get(API, headers=headers)
25 + f_step_api=getAPI.json()
26 + t_score=0
27 + for i in range(0,10):
28 + if (f_step_api["participantIdentities"][i]["player"]["accountId"]==ac_id):
29 + if f_step_api["participants"][i]["stats"]["deaths"]==0:
30 + t_score=round((f_step_api["participants"][i]["stats"]["kills"]*3+f_step_api["participants"][i]["stats"]["assists"]*0.5)/\
31 + 1,2)+round(f_step_api["participants"][i]["stats"]["totalMinionsKilled"]\
32 + /(f_step_api["gameDuration"]/60)*0.2,2)+round(f_step_api["participants"][i]["stats"]["visionScore"]*0.05,2)
33 + else:
34 + t_score=round((f_step_api["participants"][i]["stats"]["kills"]*3+f_step_api["participants"][i]["stats"]["assists"]*0.5)/\
35 + (f_step_api["participants"][i]["stats"]["deaths"]*3),2)+round(f_step_api["participants"][i]["stats"]["totalMinionsKilled"]\
36 + /(f_step_api["gameDuration"]/60)*0.2,2)+round(f_step_api["participants"][i]["stats"]["visionScore"]*0.05,2)
37 + i=10
38 + return t_score
39 +
1 +import Get_Account_Id
2 +import Get_Game_Id
3 +import check_score
4 +import requests
5 +APIKEY=Get_Account_Id.return_key()
6 +headers = {
7 + "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",
8 + "Accept-Language": "ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7",
9 + "Accept-Charset": "application/x-www-form-urlencoded; charset=UTF-8",
10 + "Origin": "https://developer.riotgames.com",
11 + "X-Riot-Token": APIKEY
12 + }
13 +def game_result(num):
14 + champid=Get_Game_Id.get_champ_id(num)
15 + gameid=Get_Game_Id.get_game_id(num)
16 + API="https://kr.api.riotgames.com/lol/match/v4/matches/" + str(gameid)
17 + getAPI=requests.get(API, headers=headers)
18 + LOL_API_DATA=getAPI.json()
19 + result=" "
20 + for i in range(0,10):
21 + if LOL_API_DATA["participants"][i]["championId"]==champid:
22 + if LOL_API_DATA["participants"][i]["stats"]["win"]==True:
23 + result="승리"
24 + else:
25 + result="패배"
26 + return result
27 +
28 +def match_user_name_and_opscore(num):
29 + gameid=Get_Game_Id.get_game_id(num)
30 + API="https://kr.api.riotgames.com/lol/match/v4/matches/" + str(gameid)
31 + getAPI=requests.get(API, headers=headers)
32 + LOL_API_DATA=getAPI.json()
33 + record_name=[]
34 + record_opscore=[]
35 + for i in range(0,10):
36 + record_name.append(LOL_API_DATA["participantIdentities"][i]["player"]["summonerName"])
37 + print(record_name)
38 + ac_id=LOL_API_DATA["participantIdentities"][i]["player"]["accountId"]
39 + record_opscore.append(check_score.op_score(ac_id))
40 + print(record_opscore)
41 + return record_name,record_opscore
42 +for j in range(0,10):
43 + print(game_result(j))
44 + lst1=[]
45 + lst2=[]
46 + lst1,lst2=match_user_name_and_opscore(j)
47 + print(lst1)
48 + print(lst2)