def get_summoner_rank(summonerId): waitApiRequest("league-v4", "by-summoner") print("Getting summoner rank for match labeling...", flush=True) url = LOL_API_BASE_URL + GET_SUMMONER_RANK_PATH + summonerId + "?api_key=" + API_KEY response = requests.get(url) # If the summonerId isn't found anymore (moved servers?) if response.status_code == 404: print("Could not get rank from summonerId") return {} # Try again if it didn't go through if response.status_code != 200: print(response.text) print("Get summoner rank failed with response code:", response.status_code) # Wait for messages to clear if rate limited if response.status_code == 429: waitApiClear("league-v4", "by-summoner") return get_summoner_rank(summonerId) rank = {} queueEntries = response.json() for queueEntry in queueEntries: if queueEntry["queueType"] == CHALLENGER_QUEUE: rank["tier"] = queueEntry["tier"] rank["rank"] = queueEntry["rank"] rank["leaguePoints"] = queueEntry["leaguePoints"] rank["rankMapping"] = TIER_MAPPING.get(rank["tier"], -1) break print("Found summoner rank:", rank) return rank
def get_player_match_info(encryptedAccountId): waitApiRequest("match-v4", "matchlists") print("Getting matches for player with encrypted account id...", flush=True) url = LOL_API_BASE_URL + GET_MATCHES_PATH + encryptedAccountId + "?queue=420&api_key=" + API_KEY response = requests.get(url) # If the accountId isn't found anymore (moved servers?) if response.status_code == 404: print("Encrypted account id not found, skipping seed") return None # Try again in 10 * RATE_LIMIT seconds if it didn't go through if response.status_code != 200: print(response.text) print("Pull player match info request failed with code:", response.status_code) # Wait for messages to clear if rate limited if response.status_code == 429: waitApiClear("match-v4", "matchlists") return get_player_match_info(encryptedAccountId) matches = response.json()["matches"] print("Found", len(matches), "matches") return matches
def get_match_data(matchId): match_data = {} url = LOL_API_BASE_URL + GET_MATCH_PATH + str( matchId) + "?api_key=" + API_KEY waitApiRequest("match-v4", "matches") response = requests.get(url) match = response.json() # If the matchId isn't found anymore (too old now?), skip! if response.status_code == 404: print("Match id not found, skipping seed") return None # Try again if it didn't go through if response.status_code != 200: print(response.text) print("Pull match request failed with code:", response.status_code) # Wait for messages to clear if rate limited if response.status_code == 429: waitApiClear("match-v4", "matches") return get_match_data(matchId) # Get player non specific data match_data["gameId"] = matchId match_data["gameCreation"] = match["gameCreation"] match_data["gameDuration"] = match["gameDuration"] # Get player specific data players = [] for pIden in match["participantIdentities"]: player = {} player["id"] = pIden["participantId"] p = match["participants"][player["id"] - 1] player["team"] = int(200 == p["teamId"]) player["champion"] = p["championId"] player["spell1"] = p["spell1Id"] player["spell2"] = p["spell2Id"] player["role"] = p["timeline"]["role"] player["lane"] = p["timeline"]["lane"] player["stats"] = p["stats"] player["accountId"] = pIden["player"]["accountId"] player["summonerId"] = pIden["player"]["summonerId"] players.append(player) match_data["players"] = players # Get match outcome outcome = match["teams"][0]["win"] == "Fail" if match["teams"][0]["teamId"] == 200: outcome = not outcome match_data["outcome"] = outcome # Print match data for debugging purposes (must import from pulldata.py) #print_match(players, outcome) return match_data
def get_encrypted_account_id(summonerName, tagLine): waitApiRequest("account", "by-riot-id") print("Pulling PUUID for from summonerName, tagline pair...", flush=True) url = RIOT_API_BASE_URL + GET_PUUID_PATH + summonerName + "/" + tagLine + "?api_key=" + API_KEY response = requests.get(url) waitApiRequest("summoner", "by-puuid") print("Pulling encrypted account id from PUUID...", flush=True) url = LOL_API_BASE_URL + GET_ACCOUNT_PATH + response.json( )["puuid"] + "?api_key=" + API_KEY response = requests.get(url) return response.json()["accountId"]
def get_challenger_summoners(): waitApiRequest("league-v4", "challengerleagues") print("Getting challenger summoners...", flush=True) url = LOL_API_BASE_URL + GET_CHALLENGER_LEAGUE_PATH + CHALLENGER_QUEUE + "?api_key=" + API_KEY response = requests.get(url) print("Challenger summoners retrieved", flush=True) # Try again in 10 * RATE_LIMIT seconds if it didn't go through if response.status_code != 200: print(response.text) print("Get challenger summoners request failed with code:", response.status_code, flush=True) # Wait for messages to clear if rate limited if response.status_code == 429: waitApiClear("league-v4", "challengerleagues") return get_challenger_summoners() summonerIds = [] for entry in response.json()["entries"]: summonerIds.append((entry["leaguePoints"], entry["summonerId"])) return summonerIds
def get_summoner_account_id(summonerId): waitApiRequest("summoner-v4", "summoners") url = LOL_API_BASE_URL + GET_SUMMONER_PATH + summonerId + "?api_key=" + API_KEY response = requests.get(url) # Fail if the server can't find the summoner if response.status_code == 404: print("Account id lookup request 404, skipping account") return None # Try again if it didn't go through if response.status_code != 200: print(response.text) print("Get summoner account id failed with code:", response.status_code, flush=True) # Wait for messages to clear if rate limited if response.status_code == 429: waitApiClear("summoner", "summoners") return get_summoner_account_id(summonerId) return response.json()["accountId"]