def average_neutrals_killed(player_id): r = Request(api_key) stats = r.get_stats_summary_from_id(player_id, 'na', 'SEASON3') for item in stats['playerStatSummaries']: if item['playerStatSummaryType'] == 'RankedSolo5x5': total = item['wins'] + item['losses'] num_creeps = item['aggregatedStats']['totalNeutralMinionsKilled'] return float(num_creeps)/float(total)
def get_player_object(player_id): obj = {} r = Request(api_key) player_name = r.get_name_from_id(player_id) obj['name'] = player_name obj['summoner_id'] = player_id obj['champ_vector'] = set_vector(player_name) obj['tier'], obj['rank'] = get_rank_and_tier_from_id(player_id) obj['avg_neutrals'] = average_neutrals_killed(player_id) return obj
def main(): # Initialize your Request class by passing in the api key - visit https://developer.riotgames.com/sign-in in order to register for yours! r = Request(api_key) # Calling a function involves passing in a name whenever a function asks for it - all API calls will have a method that takes a summoner name as a sole argument player_id = r.get_id_from_name('The Rain Man') print player_id # Most functions return a dict or list of dicts. Most functions will take summoner ID's or player names as parameters masteries = r.get_masteries_from_id(player_id) print type(masteries) print type(masteries['pages']) # All summoner-based calls assume NA region. If you want another region, just pass it in after the summoner name current_runes = r.get_current_runes_from_name('Froggen', 'euw') print current_runes['name'] # Asking for any multi-page info (like teams or stats) of a player returns a multi-page json DTO teams = r.get_teams_from_name('Dyrus') print teams[0]['name'] # Asking for ranked stats or a player's stat summary will require a season, defaulted to season 4. As of this writing, season 4 has not started yet, so calling the default stat functions will not return anything particularly useful - pass in 'SEASON3' in order to get the previous season's statistics. stats = r.get_ranked_summary_from_name('TheOddOne','na', 'SEASON3') print stats['champions'][0]['stats'] # Getting all champions doesn't require a player name, but it requires a region and an optional free-to-play argument # Calling get_champions() with no arguments will return all champions with regards to the North American Server champs = r.get_champions(True, 'na') print len(champs['champions'])
def get_played_champs_in_order_from_name(player_name): r = Request(api_key) ranked_obj = r.get_ranked_summary_from_name(player_name, 'na', 'SEASON3') return get_played_champs_in_order(ranked_obj)
def get_rank_and_tier_from_id(player_id): r = Request(api_key) for item in r.get_leagues_from_id(player_id)[str(player_id)]['entries']: if item['playerOrTeamId'] == str(player_id): return item['tier'], item['rank']