def create_player(summoner_id, sum_dict, league_dict, region): """Creates and returns Player object from inputs Args: summoner_id: String representing player's ID ([0-9]+) sum_dict: Dictionary containing league_dict: Dictionary region: String (2 letters) representing player's region (e.g. 'na') Returns: p: Player instance (see champs.models.py) Dependencies: Player sum_name_standardize get_player_from_league rank_to_num """ # If player is unranked, their key won't exist in league_dict player_dict = get_player_from_league(summoner_id, league_dict) tier = player_dict['tier'] division = player_dict['entries'][0]['division'] # Get info from sum_dict summoner_name = sum_dict[summoner_id]['name'] summoner_level = sum_dict[summoner_id]['summonerLevel'] profile_icon_id = sum_dict[summoner_id]['profileIconId'] last_revision = sum_dict[summoner_id]['revisionDate'] # Get info from player_dict lp = player_dict['entries'][0]['leaguePoints'] wins = player_dict['entries'][0]['wins'] losses = player_dict['entries'][0]['losses'] # Standardize summoner name (all lowercase, no spaces) std_summoner_name = sum_name_standardize(summoner_name) # Get rank as a number from player's tier & division rank_num=rank_to_num(tier, division) # Create and return Player p = Player( summoner_id=summoner_id, summoner_name=summoner_name, profile_icon_id=profile_icon_id, last_revision=last_revision, summoner_level=summoner_level, region=region, std_summoner_name=std_summoner_name, tier=tier, division=division, rank_num=rank_num, lp=lp, wins=wins, losses=losses ) return p
def home(request): if request.method == 'POST': form = NameForm(request.POST) if form.is_valid(): summoner_name = form.cleaned_data['summoner_name'] std_summoner_name = sum_name_standardize(summoner_name) player = Player.objects.get(std_summoner_name=std_summoner_name) summoner_to_db_display(std_summoner_name, player.region, player.summoner_id) return HttpResponseRedirect('/champs/summoner/{}/'.format(std_summoner_name)) else: form = NameForm() return render(request, 'champs/home.html', {'form': form})
def master_to_db(region='na'): master_list = api.get_master(region=region) for master in master_list: std_name = sum_name_standardize(master['playerOrTeamName']) sum_id = master['playerOrTeamId'] summoner_to_db_display(std_name, region, sum_id)
def challenger_to_db(region='na'): challenger_list = api.get_challenger(region=region) for challenger in challenger_list: std_name = sum_name_standardize(challenger['playerOrTeamName']) sum_id = challenger['playerOrTeamId'] summoner_to_db_display(std_name, region, sum_id)