Coding/Riot API를 사용하여 lolchess.gg 클론 코딩
라이엇 api를 사용하여 TFT(롤토체스) 데이터 수집 -3
zaraxxus
2023. 2. 6. 00:50
1.한국 챌린져 큐의 최근 게임 정보 가져오기
1-3) 챌린져들의 puuid로 matchid 가져오기
이제 챌린져들의 게임을 가져와봅시다! 각 챌린져 마다 10경기만 가져오도록 하겠습니다.(300 x 10 경기입니다)
def match_v1_get_list_match_id(puuid, start, count):
url = f"https://asia.api.riotgames.com/tft/match/v1/matches/by-puuid/{puuid}/ids?start={start}&count={count}"
r = get_r(url)
if r.status_code == 200:
pass
elif r.status_code == 429 or r.status_code == 502:
if r.status_code == 429:
print("api cost full : infinite loop start")
if r.status_code == 502:
print(" 502 error : infinite loop start")
start_time = time.time()
i = 1
while True:
if r.status_code == 429 or r.status_code == 502:
print(f"try 10 seconds wait time: {i} loops - {r.status_code} error")
time.sleep(10)
i = i + 1
r = get_r(url)
elif r.status_code == 200:
print("total wait time :", time.time() - start_time)
break
else:
print("failed:", r.status_code)
if r.status_code == 403:
print("you need api renewal !!")
exit()
return r.json()
def get_match_ids(df):
print("start - get match ids")
matchids = []
start = time.time()
for i, puuid in enumerate(df["puuid"]):
if puuid is not None:
try:
puuid_data = match_v1_get_list_match_id(puuid, 0, match_number)
matchids.append(puuid_data)
print(f"success matchids - location : {i}")
except Exception as e:
print(f"error ids - location : {i}")
print(e)
pass
end = time.time()
print(f"success - matchids : {end - start:.2f} sec")
return matchids
match_number = 10
data = challenger_data()
matchids = get_match_ids(data)
로 02.06에 jupyter notebook에서 작동 확인했습니다 :)
여기서부턴 api cost 때문에 429 error를 기다려야합니다
(상위 100명만 가져오면 안 기다려도 됩니다)
다음과 같이 각 챌린져 마다 10경기 씩 가져와 지면 성공입니다!
코스트 때문에 한번 돌리는데 대략 5분이나 걸리네요..