Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import secrets
from xmlrpc.client import Boolean
import requests
## gets summoner id or puuid by name
def get_summoner_id(summoner, puuid=Boolean):
## takes 2 arguments, summoner name and a bool, returns either the puuid or id which we need to other API calls
url = f'https://euw1.api.riotgames.com/lol/summoner/v4/summoners/by-name/{summoner}?api_key={secrets.riot_api_key}'
response = requests.get(url).json()
if puuid == False:
return response['id']
elif puuid == True:
return response['puuid']
## gets champion name by id
def get_champion_name_by_id(id):
## takes in an id as argument and returns the champion's name
url = f'http://ddragon.leagueoflegends.com/cdn/12.20.1/data/en_US/champion.json'
response = requests.get(url).json()
datadragon = response['data']
for champion in datadragon:
if str(id) == datadragon[champion]['key']:
return champion
## gets top five most played champions
def get_top5(summoner):
summoner = get_summoner_id(summoner,False)
url = f'https://euw1.api.riotgames.com/lol/champion-mastery/v4/champion-masteries/by-summoner/{summoner}?api_key={secrets.riot_api_key}'
response = requests.get(url).json()
most_played = []
for champion in response[0:5]:
champion_name = get_champion_name_by_id(champion['championId'])
most_played.append(champion_name)
return most_played
## gets last 10 games can adjust for up to last 100 games
def get_match_history(summoner):
puuid = get_summoner_id(summoner,True)
url = f'https://europe.api.riotgames.com/lol/match/v5/matches/by-puuid/{puuid}/ids?start=0&count=10&api_key={secrets.riot_api_key}'
match_history = requests.get(url).json()
return match_history
## gets ranked stats
def get_summoner_stats(summoner):
summoner = get_summoner_id(summoner,False)
url =f'https://euw1.api.riotgames.com/lol/league/v4/entries/by-summoner/{summoner}?api_key={secrets.riot_api_key}'
response = requests.get(url).json()
data = response[0]
tier = data['tier']
rank = data['rank']
league_points = str(data['leaguePoints']) + 'LP'
winrate = str(round(data['wins']/(data['wins']+data['losses'])*100,2))+'%'
streak = data['hotStreak']
ranked_stats = [tier,rank,league_points,winrate]
if streak == True:
ranked_stats.append(streak)
return (ranked_stats)
""" def get_game_data(summoner):
summoner = get_summoner_id(summoner,False)
url = f'https://euw1.api.riotgames.com/lol/spectator/v4/active-games/by-summoner/{summoner}?api_key={secrets.riot_api_key}'
match_data = requests.get(url).json()
participants = match_data['participants']
for player in participants:
player_champion = (get_champion_by_key(player['championId']))
player_name = player['summonerName']
player_stats = get_summoner_stats(player_name)
champion_mastery = get_champion_mastery(player_name,player['championId'])
print(f'{player_name}: {player_stats}\nPlaying: {player_champion}\n{champion_mastery}\n')
get_game_data('WD Mozart') """