if league_info['queue'] == 'RANKED_SOLO_5x5': match_data['participantTier'][p_id] = league_info['tier'] if p_id not in unpulled_summoners and p_id not in pulled_summoners: unpulled_summoners.append(p_id) except KeyError, e: print("Error occured when trying to get summoners to pull: " + str(e)) continue #add match history and stats for every participant match_data['participantStats'] = list() #needed later on stats_last_update = dict() for p_id in participants_ids: while(True): try: wait_for_request_availability(w) ranked_stats = w.get_ranked_stats(p_id) match_data['participantStats'].append(ranked_stats) stats_last_update[p_id] = ranked_stats['modifyDate'] break except Exception, e: print("Error occured when trying to get ranked stats data: " + str(e)) time.sleep(2) continue match_data['participantMatchHistory'] = dict() match_data['participantChampionMatchHistory'] = dict() match_data['participantMatchListHistory'] = dict() match_created = match_data['matchCreation']
print('static tests passed') status_tests() print('status tests passed') champion_tests() print('champion tests passed') s = summoner_tests(summoner_name) print('summoner tests passed') game_tests(s) print('game tests passed') league_tests(s) print('league tests passed') stats_tests(s) print('stats tests passed') team_tests(s) print('team tests passed') m = match_history_tests(s) print('match history tests passed') match_tests(m) print('match passed') print('all tests passed, w00t. if only they were better tests...') summoner = w.get_summoner(name=summoner_name) wait() print w.get_stat_summary(summoner['id']) wait() print w.get_ranked_stats(summoner['id']) if __name__ == '__main__': main()
class Lol: def __init__(self, key, default_region=EUROPE_WEST): self.lol_watcher = RiotWatcher(key, default_region=default_region) self.wait() self.champion_list = self.lol_watcher.static_get_champion_list( )['data'] def wait(self): while not self.lol_watcher.can_make_request(): time.sleep(1) def test_map(self, _id): if _id == 1: return "Summoner's Rift" elif _id == 2: return "Summoner's Rift" elif _id == 3: return "The Proving Grounds (tuto)" elif _id == 4: return "Twisted Treeline" elif _id == 8: return "The Crystal Scar" elif _id == 10: return "Twisted Treeline" elif _id == 11: return "Summoner's Rift" elif _id == 12: return "Howling Abyss" elif _id == 14: return "Butcher's Bridge" def test_queue(self, _id): if _id == 0: return "Custom" elif _id == 2: return "Normal 5v5 blind" elif _id == 4: return "Ranked Solo 5v5" elif _id == 6: return "Ranked Premade 5v5" elif _id == 7: return "Coop vs ia 5v5" elif _id == 8: return "Normal 3v3" elif _id == 9: return "Ranked flex" elif _id == 14: return "Normal Draft 5v5" elif _id == 16: return "Odin 5v5 Blind" elif _id == 17: return "Odin 5v5 Draft" elif _id == 25: return "Coop vs ia 5v5" elif _id == 31: return "Coop vs ia (intro)" elif _id == 32: return "Coop vs ia (beginner)" elif _id == 33: return "Coop vs ia (Intermediate)" elif _id == 41: return "Ranked Team 3v3" elif _id == 52: return "Ranked Team 5v5" elif _id == 61: return "GROUP_FINDER_5v5" elif _id == 65: return "Aram" elif _id == 70: return "One For All" elif _id == 72: return "FIRSTBLOOD_1v1" elif _id == 73: return "FIRSTBLOOD_2v2" elif _id == 75: return "Hexakill" elif _id == 76: return "URF" elif _id == 78: return "One For All" elif _id == 83: return "Bot URF" elif _id == 91: return "DOOM Bot (rank 1)" elif _id == 92: return "DOOM Bot (rank 2)" elif _id == 93: return "DOOM Bot (rank 5)" elif _id == 96: return "Ascension" elif _id == 98: return "Hexakill" elif _id == 100: return "BILGEWATER_ARAM_5v5" elif _id == 300: return "Poro King" elif _id == 310: return "COUNTER_PICK" elif _id == 313: return "BILGEWATER_5v5" elif _id == 315: return "Siege" elif _id == 317: return "Definitly Not Dominion" elif _id == 318: return "Aram URF" elif _id == 400: return "Normal Draft" elif _id == 410: return "Ranked" elif _id == 420: return "Ranked Solo/Duo" elif _id == 440: return "Ranked Flex" def test_champ(self, _id): temp = [] for k in self.champion_list: temp.append(self.champion_list[k]) temp = [nb for nb in temp if nb['id'] == _id] return temp[0]['name'] def test_ranked_stats(self, stats, key): stats = stats['champions'] stats = [nb for nb in stats if nb['id'] == 0] stats = stats[0]['stats'] return stats[key] def test_team(self, _id): if _id == 100: return ":large_blue_circle:" else: return ":red_circle:" def check_lol(self, player, region): try: self.wait() return self.lol_watcher.get_summoner(name=player, region=region) except LoLException as e: if e == error_429: return ":x: Resseye dans {} secondes.".format( e.headers['Retry-After']) elif e == error_404: return ":x: Summoner inconnu : {}".format(player) def message_lol(self, summoner): message = ":information_source: {} :video_game:\n\n".format( summoner['name']) message += " :information_source: Général Stats\n" message += " **ID**: {}\n".format(summoner['id']) message += " **Level**: {}\n".format(summoner['summonerLevel']) self.wait() temp = self.lol_watcher.get_league(summoner_ids=[summoner['id']]) rank = [] for i in temp[str(summoner['id'])]: rank.append(i['queue'] + " " + i['tier']) message += " **Rank**: {}\n".format(rank) #message += " **Mastery Levels**: {}\n".format() #message += " **Mastery Points**: {}\n".format() #message += " **Mastery Tokens**: {}\n".format() self.wait() player_stats = self.lol_watcher.get_stat_summary( summoner['id'])['playerStatSummaries'] player_stats = [ nb for nb in player_stats if nb['playerStatSummaryType'] == 'Unranked' ] player_stats = player_stats[0] message += " **Wins**: {}\n".format(player_stats['wins']) message += " **Kills**: {}\n".format( player_stats['aggregatedStats']['totalChampionKills']) message += " **Assistances**: {}\n".format( player_stats['aggregatedStats']['totalAssists']) message += " **Creeps tués**: {}\n".format( player_stats['aggregatedStats']['totalMinionKills']) message += " **Tourelles détruite**: {}\n\n".format( player_stats['aggregatedStats']['totalTurretsKilled']) #message += " **Dernière connexion**: {}\n\n".format() message += ":information_source: Ranked Stats :\n" try: self.wait() ranked_stats = self.lol_watcher.get_ranked_stats(summoner['id']) message += " **Win:** {}\n".format( self.test_ranked_stats(ranked_stats, 'totalSessionsWon')) message += " **Loose:** {}\n".format( self.test_ranked_stats(ranked_stats, 'totalSessionsLost')) message += " **Kill:** {}\n".format( self.test_ranked_stats(ranked_stats, 'totalChampionKills')) message += " **Assistance:** {}\n".format( self.test_ranked_stats(ranked_stats, 'totalAssists')) message += " **Damages infligés:** {}\n".format( self.test_ranked_stats(ranked_stats, 'totalDamageDealt')) message += " **Damages Reçus:** {}\n".format( self.test_ranked_stats(ranked_stats, 'totalDamageTaken')) message += " **Argent gagné:** {}\n".format( self.test_ranked_stats(ranked_stats, 'totalGoldEarned')) message += " **Creeps tués:** {}\n".format( self.test_ranked_stats(ranked_stats, 'totalMinionKills')) message += " **Tourelles détruites:** {}\n".format( self.test_ranked_stats(ranked_stats, 'totalTurretsKilled')) message += " **Double kills:** {}\n".format( self.test_ranked_stats(ranked_stats, 'totalDoubleKills')) message += " **Triple kills:** {}\n".format( self.test_ranked_stats(ranked_stats, 'totalTripleKills')) message += " **Quadra kills:** {}\n".format( self.test_ranked_stats(ranked_stats, 'totalQuadraKills')) message += " **Penta kills:** {}\n".format( self.test_ranked_stats(ranked_stats, 'totalPentaKills')) message += " **Total Killing Spree:** {}\n\n".format( self.test_ranked_stats(ranked_stats, 'killingSpree')) except: message += "**Aucune Stats de Ranked n'a été trouvée !**\n\n" message += ":information_source: Game en cours :\n" try: self.wait() temp = self.lol_watcher.get_current_game(summoner['id']) message += " **ID Partie:** {}\n".format(temp['gameId']) message += " **GameMode:** {}\n".format(temp['gameMode']) message += " **GameType:** {}\n".format(temp['gameType']) message += " **ID Queue:** {}\n".format( self.test_queue(temp['gameQueueConfigId'])) message += " **ID Platform:** {}\n".format(temp['platformId']) message += " **ID Map:** {}\n".format(self.test_map(temp['mapId'])) for i in temp['participants']: message += " " + i['summonerName'] + " (" + self.test_champ( i['championId']) + ") Team: " + self.test_team( i['teamId']) + "\n" except: message += "**Aucune game en cours...**" return message
def main(): #my_riot_api_key = str(raw_input('\nPaste Riot API Key: ')) #my_championgg_api_key = str(raw_input('\nPaste champion.gg API Key: ')) my_riot_api_key = '8792f2e9-2e9e-4f23-81bd-a219f81ea98f' my_championgg_api_key = '3f9e409bd58bc1868f8bfc4a3a75d40c' w = RiotWatcher(my_riot_api_key) c = championggAPI(my_championgg_api_key) #print('\nInput API Key can make requests?') #print(w.can_make_request()) summoner_to_check = str(raw_input('\nWhat summoner do you want to know about? ')) summoner = w.get_summoner(name=summoner_to_check) #print(summoner) my_mastery_pages = w.get_mastery_pages([summoner['id'], ])[str(summoner['id'])] show_masteries = str(raw_input('Show current masteries? ')) len_mastery_data = len(my_mastery_pages['pages']) if show_masteries == 'Yes': for x in range(0, len_mastery_data): if my_mastery_pages['pages'][x]['current']: current_mastery_page = my_mastery_pages['pages'][x] print ('Current masteries: ') print '\"{name}\"'.format(name=current_mastery_page['name']) mastery = MasteryPageParsing(current_mastery_page) m = mastery.tree_divider() print m elif show_masteries == 'yes': for x in range(0, len_mastery_data): if my_mastery_pages['pages'][x]['current']: current_mastery_page = my_mastery_pages['pages'][x] print ('Current mastery page: ') print '\"{name}\"'.format(name=current_mastery_page['name']) mastery = MasteryPageParsing(current_mastery_page) m = mastery.tree_divider() print m my_rune_pages = w.get_rune_pages([summoner['id'], ])[str(summoner['id'])] show_runes = str(raw_input('Show current runes? ')) len_rune_data = len(my_rune_pages['pages']) if show_runes == 'Yes': for x in range(0, len_rune_data): if my_rune_pages['pages'][x]['current']: current_rune_page = my_rune_pages['pages'][x] print ('Current rune page: ') print '\"{name}\"'.format(name=current_rune_page['name']) runes = RunePageParsing(current_rune_page) r = runes.rune_descriptions() print r elif show_runes == 'yes': for x in range(0, len_rune_data): if my_rune_pages['pages'][x]['current']: current_rune_page = my_rune_pages['pages'][x] print ('Current runes: ') print '\"{name}\"'.format(name=current_rune_page['name']) runes = RunePageParsing(current_rune_page) r = runes.rune_descriptions() print r champ_to_check = str(raw_input('\nWhat champion are they on? ')) role_of_champ = str(raw_input('What role are they in? (Valid inputs: Top, Jungle, Middle, ADC, Support) ')) championID = CONSTS.CHAMPION_ID[champ_to_check] #print ('{cha}\'s championID: {id}').format(cha=champ_to_check, id=championID) champion_mastery = ChampionMastery(my_riot_api_key) r = champion_mastery.get_champion_mastery(summoner['id'], championID) print'{name} is level {level} on {champ}'.format(name=summoner['name'], level=r['championLevel'], champ=champ_to_check) ranked_champion_stats = w.get_ranked_stats(summoner['id']) length_ranked_data = len(ranked_champion_stats['champions']) champ_found = False for x in range(0, length_ranked_data): if ranked_champion_stats['champions'][x]['id'] == int(championID): champ_games_won = float(ranked_champion_stats['champions'][x]['stats']['totalSessionsWon']) #print 'champ games won', champ_games_won champ_games_lost = float(ranked_champion_stats['champions'][x]['stats']['totalSessionsLost']) #print 'games lost', champ_games_lost champ_games_played = float(ranked_champion_stats['champions'][x]['stats']['totalSessionsPlayed']) winrate = round((champ_games_won / champ_games_played) * 100, 3) if champ_games_played > 5: if 60 <= winrate: winrate_reaction = 'strong' elif 50 <= winrate < 60: winrate_reaction = 'good' elif 40 <= winrate < 50: winrate_reaction = 'bad' else: winrate_reaction = 'ebolAIDS-causing, cancer-giving, hope-sundering' else: winrate_reaction = 'unreliable' print '{name} on {champ} has a {reac} winrate of {rate}% with {num} games played.'.format(name=summoner['name'], champ=champ_to_check, reac=winrate_reaction, rate=winrate, num=champ_games_played) champ_found = True champ_stats = c.request_by_champion(champ_to_check) champ_winrate = 'unable to be found.' length_champion_ranked_data = len(champ_stats) for y in range(0, length_champion_ranked_data): if champ_stats[y]['role'] == role_of_champ: champ_winrate = float(champ_stats[y]['general']['winPercent']) print 'Average winrate for {champ} as {role} is {winrate}.'.format(champ=champ_to_check, role=role_of_champ, winrate=champ_winrate) calc = winrate_calcuations(summoner['name']) calc.winrate_difference(winrate, champ_winrate) if champ_found is False: print 'No ranked champion data found for {champ}\n'.format(champ=champ_to_check)
w = RiotWatcher('<Insert Your API Key Here>') # check if we have API calls remaining print(w.can_make_request()) with open('allnames3.csv', 'r+') as f: fNew = open('player_data.csv', 'w+') while (True): line = f.readline() if line != "": #split data into player information time.sleep(1.75) line_data = line.replace('\n', '').split(', ') print(line_data) #Player Id is index 0 #Try to get data, if none, then don't write anything try: player_stats = w.get_ranked_stats(line_data[0]) except: #For rate limiting issues continue #Write all the data found into a csv format fNew.write(line_data[0] + ', ' + line_data[1] + ', ') # Write all the data for each champion down. for champion in player_stats['champions']: fNew.write('Champion id, ' + str(champion['id']) + ', ') for data in champion['stats']: fNew.write( str(data) + ', ' + str(champion['stats'][data]) + ', ') fNew.write('\n') else: break fNew.close()
if p_id not in unpulled_summoners and p_id not in pulled_summoners: unpulled_summoners.append(p_id) except KeyError, e: print( "Error occured when trying to get summoners to pull: " + str(e)) continue #add match history and stats for every participant match_data['participantStats'] = list() #needed later on stats_last_update = dict() for p_id in participants_ids: while (True): try: wait_for_request_availability(w) ranked_stats = w.get_ranked_stats(p_id) match_data['participantStats'].append(ranked_stats) stats_last_update[p_id] = ranked_stats['modifyDate'] break except Exception, e: print( "Error occured when trying to get ranked stats data: " + str(e)) time.sleep(2) continue match_data['participantMatchHistory'] = dict() match_data['participantChampionMatchHistory'] = dict() match_data['participantMatchListHistory'] = dict() match_created = match_data['matchCreation']
from riotwatcher import LATIN_AMERICA_SOUTH from riotwatcher import RiotWatcher from riotwatcher import LoLException from dataRunes import dataRunes from dataMasteries import dataMasteries # Create your views here. ''' Aqui esta toda la logica de todos los pedidos a la API de league Of Leagends. Por temas de comodidad se utilizo la herramienta Riot Watcher, sirve para hacer los pedidos mediante funciones de Python.''' riotWatcher = RiotWatcher("98f4f837-c794-4a58-bcb7-b436873a03d2", default_region=LATIN_AMERICA_SOUTH) me = riotWatcher.get_summoner(name='sadjockerking')#Se le agradece a Sad Jocker King por prestar su cuenta try: rankedst = riotWatcher.get_ranked_stats(me['id']) x = int(len(rankedst['champions'])) - 1 except(LoLException): rankedst = {} x = 0 def home(request): free_to_play = True context = RequestContext(request) # sumInf = summonerInfo() # mpcInf = mostPlayedChampInfo() # featgames = featuredGames() # free = freeChamps() # his = history() totalInfo = {} # runas = runes()
# but at the same time, they don't change often.... #static_champ_list = w.static_get_champion_list() #print(static_champ_list) # import new region code from riotwatcher import EUROPE_WEST # request data from EUW euw = RiotWatcher('RGAPI-62c12c6d-5a21-4d8e-96b2-c3cad4aa9baa', default_region=EUROPE_WEST) Manismyforte = euw.get_summoner(name='Manismyforte') #Manismyforte = euw.get_summoner(name='Manismyforte', region=EUROPE_WEST) print(Manismyforte) my_ranked_stats = euw.get_ranked_stats(me['id']) #froggen = w.get_summoner(name='froggen', region=EUROPE_WEST) #print(froggen) # create watcher with EUW as its default region #euw = RiotWatcher('RGAPI-62c12c6d-5a21-4d8e-96b2-c3cad4aa9baa', default_region=EUROPE_WEST) # proper way to send names with spaces is to remove them, still works with spaces though #xpeke = w.get_summoner(name='fnaticxmid') #print(xpeke) #xpeke = w.get_summoner(name='fnaticxmid') #print(xpeke) # Error checking requires importing LoLException as well as any errors you wish to check for.