1.한국 챌린져 큐의 최근 게임 정보 가져오기
1-3-2 ) 실행이 된 matchid 의 저장
matchid 로 드디어 match history, 게임 정보를 가져오게 됩니다.
->여기서 한번 history 정보를 가져온 matchid 에 대해서 다시 이러한 작업을 반복하기 싫어
matchids_saved 라는 histroy를 가져온 matchid를 저장하는 파일을 나중에 만들 것이고,
아래 코드는 해당 파일 유무에 따라 다음 함수가 실행되도록 만들었습니다.
(생략해도 되는 부분입니다, 생략 시 뒤에 코드만 조금 수정해주면 됩니다.)
if os.path.isfile("data/matchids_saved.csv"):
print("Have saved file !!")
saved_matchids_df = pd.read_csv("data/matchids_saved.csv")
saved_matchids = saved_matchids_df["matchid"].to_list()
else:
saved_matchids = []
sorted_matchids = sort_matchids(matchids, saved_matchids)
1-4 ) matchid의 분류
matchid를 분류하는 함수입니다.
앞선 글에서 본 파일과 같이 한 명의 챌린져의 최근 10경기가 list 형태로 가져와지니
2번째 줄 : list 를 일단 모두 풀어준 후,
3번째 줄 : 챌린져들 끼리 만나는 중복 된 경기가 있을 것이기 때문에 set 처리를 해주고
4,5 번째줄 : 그 후 저장되있던 파일을 차집합으로 빼주기 위해 set 처리 해주고 다음과 같이 작성하였습니다
from itertools import chain
def sort_matchids(matchids, saved_matchids):
matchids2 = list(chain(*matchids))
matchids3 = set(matchids2)
matchids_saved = set(saved_matchids)
new_matchids = matchids3 - matchids_saved
matchids4 = list(new_matchids)
matchids4 = sorted(matchids4, reverse=True)
print(f"sorted match ids: {len(matchids4)}")
return matchids4
그렇게 이제 match history를 가져 올 sorted_matchids (new_matchids) 를 얻었습니다!
저는 이미 수집 중인 파일이 있어서 새롭게 1238개의 새로운 matchid를 얻네요

'Coding > Riot API를 사용하여 lolchess.gg 클론 코딩' 카테고리의 다른 글
라이엇 api를 사용하여 TFT(롤토체스) 데이터 수집 -6 (0) | 2023.02.08 |
---|---|
라이엇 api를 사용하여 TFT(롤토체스) 데이터 수집 -5 (0) | 2023.02.07 |
라이엇 api를 사용하여 TFT(롤토체스) 데이터 수집 -3 (0) | 2023.02.06 |
라이엇 api를 사용하여 TFT(롤토체스) 데이터 수집 -2 (0) | 2023.02.02 |
롤체지지 클론코딩 - 완성본 (0) | 2023.02.02 |