수업 소개
그동안 수집한 매치 아이디를 활용해 롤 데이터를 대량으로 수집해봅시다. 마지막 영상 수업입니다.
강의
코드
user_gamedata.py 파일 코드
import requests
import time
import pandas as pd
import ast
import pickle
api_key = "본인의 라이엇 API KEY를 입력하세요"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 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": api_key
}
df = pd.read_csv("matchid.csv", encoding="euc-kr", index_col=0)
for index, row in df.iterrows():
tier = row["tier"]
rank = row["rank"]
matchid_list = ast.literal_eval(row["matchid"])
for matchid in matchid_list:
url = f"https://asia.api.riotgames.com/lol/match/v5/matches/{matchid}"
data = requests.get(url, headers=headers).json()
time.sleep(1)
data["tier"] = tier
data["rank"] = rank
print(data)
path = f"user_data/{index}_{matchid}.pickle"
with open(path, "wb") as f:
pickle.dump(data, f)

