Permalink
Cannot retrieve contributors at this time
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?
ChatBotGroup/riotMatches.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
114 lines (88 sloc)
5.12 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from riotRequests import * | |
from riotConverter import * | |
# Riot API documentation was used. | |
# https://developer.riotgames.com/api-methods/ and https://developer.riotgames.com/static-data.html | |
def matchList(region, summonerName): | |
"""Returns updated match list of chosen summoner by taking region and summoner name as input""" | |
summonerData = requestSummonerData(region, summonerName, APIKey) | |
accountID = str(summonerData['accountId']) | |
matchList = requestMatchListData(region, accountID, APIKey) | |
champions = [] | |
lanes = [] | |
games = [] | |
gameNum = [] # used to index from 1 instead of 0 | |
# In this case the loop is used to get the last 10 matches. | |
for i in range(10): | |
gameNum.append(i+1) | |
champion = str(matchList['matches'][i]['champion']) | |
championName = champNameByID(champion) | |
champions.append(championName) | |
lanes.append(matchList['matches'][i]['lane']) | |
game = str(matchList['matches'][i]['gameId']) | |
games.append(game) | |
# The code below was made with Tiago's help. | |
# Returns data from 3 different lists formatted in a single string. | |
listOfGames = "\n".join("{0}: {1} - {2}".format(x, y, z) for x, y, z in zip(gameNum, champions, lanes)) | |
return listOfGames | |
def matchDetails(region, summonerName, positionInList): | |
"""Returns details about selected match by taking region, summoner name and match by position in list as input""" | |
summonerData = requestSummonerData(region, summonerName, APIKey) | |
accountID = str(summonerData['accountId']) | |
matchList = requestMatchListData(region, accountID, APIKey) | |
matchID = str(matchList['matches'][positionInList-1]['gameId']) | |
matchDetails = requestMatchDetails(region, matchID, APIKey) | |
# The empty lists below are used to store data received from the API. | |
# Blue Team | |
blueTeamPlayers = [] | |
blueTeamChampions = [] | |
blueTeamGold = [] | |
blueTeamKills = [] | |
blueTeamDeaths = [] | |
blueTeamAssists = [] | |
blueTeamMinions = [] | |
# Loop used to get all the necessary data from participants with IDs 0 to 4. | |
for playerCountBlue in range(5): | |
player = str(matchDetails['participants'][playerCountBlue]['participantId']) | |
blueTeamPlayers.append(player) | |
champion = str(matchDetails['participants'][playerCountBlue]['championId']) | |
championName = champNameByID(champion) | |
blueTeamChampions.append(championName) | |
gold = str(matchDetails['participants'][playerCountBlue]['stats']['goldEarned']) | |
blueTeamGold.append(gold) | |
kills = str(matchDetails['participants'][playerCountBlue]['stats']['kills']) | |
blueTeamKills.append(kills) | |
deaths = str(matchDetails['participants'][playerCountBlue]['stats']['deaths']) | |
blueTeamDeaths.append(deaths) | |
assists = str(matchDetails['participants'][playerCountBlue]['stats']['assists']) | |
blueTeamAssists.append(assists) | |
minions = str(matchDetails['participants'][playerCountBlue]['stats']['totalMinionsKilled']) | |
blueTeamMinions.append(minions) | |
# Red Team | |
redTeamPlayers = [] | |
redTeamChampions = [] | |
redTeamGold = [] | |
redTeamKills = [] | |
redTeamDeaths = [] | |
redTeamAssists = [] | |
redTeamMinions = [] | |
# Loop used to get all the necessary data from participants with IDs 5 to 9. | |
for playerCountRed in range(5, 10): | |
player = str(matchDetails['participants'][playerCountRed]['participantId']) | |
redTeamPlayers.append(player) | |
champion = str(matchDetails['participants'][playerCountRed]['championId']) | |
championName = champNameByID(champion) | |
redTeamChampions.append(championName) | |
gold = str(matchDetails['participants'][playerCountRed]['stats']['goldEarned']) | |
redTeamGold.append(gold) | |
kills = str(matchDetails['participants'][playerCountRed]['stats']['kills']) | |
redTeamKills.append(kills) | |
deaths = str(matchDetails['participants'][playerCountRed]['stats']['deaths']) | |
redTeamDeaths.append(deaths) | |
assists = str(matchDetails['participants'][playerCountRed]['stats']['assists']) | |
redTeamAssists.append(assists) | |
minions = str(matchDetails['participants'][playerCountRed]['stats']['totalMinionsKilled']) | |
redTeamMinions.append(minions) | |
# Returns data from 7 different lists for each team formatted in a single string. | |
blueTeam = "\n".join("{0} - {1} - {2} / {3} / {4} - {5} - {6}".format(" "*(2-len(a))+a, b+" "*(12-len(b)), c+" "*(2-len(c)), d+" "*(2-len(d)), x+" "*(2-len(x)),y+" "*(7-len(y)), z) for a, b, c, d, x, y, z in zip(blueTeamPlayers,blueTeamChampions, blueTeamKills, blueTeamDeaths, blueTeamAssists, blueTeamMinions, blueTeamGold)) | |
redTeam = "\n".join("{0} - {1} - {2} / {3} / {4} - {5} - {6}".format(" "*(2-len(a))+a, b+" "*(12-len(b)), c+" "*(2-len(c)), d+" "*(2-len(d)), x+" "*(2-len(x)),y+" "*(7-len(y)), z) for a, b, c, d, x, y, z in zip(redTeamPlayers, redTeamChampions, redTeamKills, redTeamDeaths, redTeamAssists, redTeamMinions, redTeamGold)) | |
return "¬¬ Blue Team\n"+ "ID - Name - K - D - A - Minions - Gold\n" + blueTeam + "\n\n¬¬ Red Team\n"+"ID - Name - K - D - A - Minions - Gold\n" + redTeam |