Пример #1
0
    def get_summoner_info(self, summoner_name):
        """
        given a summoner name, retun the following data:

        {
            "profileIconId": 1665,
            "name": "EspinoKiller",
            "summonerLevel": 30,
            "accountId": 228772786,
            "id": 89028317,
            "revisionDate": 1500131820000
        }
        :param summoner_name: the summoner name of a player
        :return a dictionary with the info
        """
        summoner_info = get_response(
            BASE_URL.format(self.platform) +
            'summoner/v3/summoners/by-name/%s' % summoner_name)
        data = {
            'id':
            summoner_info['id'],
            'accountId':
            summoner_info['accountId'],
            'name':
            summoner_info['name'],
            'lvl':
            summoner_info['summonerLevel'],
            'icon':
            PROFILE_ICONS_URL.format(
                Configuration.get_version("champion version"),
                summoner_info['profileIconId'])
        }

        return data
Пример #2
0
    def get_several_matches_info(self, games_list):
        """
        given a match id, return the data written in "match_info" file as an example.
        this function returns the summoner match data from several of his recent rankeds or unrankeds games

        :param games_list: a sublist of games receive from function "get_summoner_recent_games" or "get_summoner_recent_rankeds"
        :return: a list of dictionaries with info about the games
        """
        info_list = []
        for game in games_list:
            game_info = get_response(
                BASE_URL.format(self.platform) +
                'match/v3/matches/%s' % game['gameId'])

            for participant in game_info['participants']:
                if participant['championId'] == game['championId']:
                    stats = participant['stats']
                    info = {
                        'win': stats['win'],
                        'kills': stats['kills'],
                        'goldEarned': stats['goldEarned'],
                        'deaths': stats['deaths'],
                        'assists': stats['assists'],
                        'champLvl': stats['champLevel'],
                        'cs': stats['totalMinionsKilled'],
                        'spell1': participant['spell1Id'],
                        'spell2': participant['spell2Id']
                    }
                    info_list.append(info)
                    break

        return info_list
def write_files():
    """
    writes the json response from the api into several files
    :return: None
    """
    for id_locale, locale in LOCALES.items():
        response = get_response(URL.format(locale))
        with open("masteries{}.json".format(locale), "w") as outfile:
            json.dump(response, outfile)
Пример #4
0
    def get_current_game_info(self, summoner_id):
        """
        given a summoner id, return the data written in current_game_info if that summoner is currently playing or
        starting a match up

        :param summoner_id: the id of the summoner
        :return: a dictionary with the desired data
        """
        current_game = {}
        current_game_info = get_response(
            BASE_URL.format(self.platform) +
            "spectator/v3/active-games/by-summoner/%s" % summoner_id)
        current_game['gameId'] = current_game_info['gameId']
        banned_champs = []
        for champ in current_game_info['bannedChampions']:
            query = session.query(Champions).get(champ['championId'])
            champion_info = {"id": query.id, "image": query.image_champion}
            banned_champs.append(champion_info)

        current_game['bannedChamps'] = banned_champs
        participants = []
        for participant in current_game_info['participants']:
            participant_data = {
                "champion":
                session.query(Champions).get(
                    participant['championId']).toJson(2),
                "summoner_name":
                participant['summonerName'],
                "summonerId":
                participant['summonerId'],
                "runes": [
                    session.query(Runes).get(rune['runeId']).toJson(
                        self.language, count=rune["count"])
                    for rune in participant['runes']
                ],
                "masteries": [
                    session.query(Masteries).get(mastery['masteryId']).toJson(
                        self.language, count=mastery["rank"])
                    for mastery in participant['masteries']
                ],
                "spell1":
                session.query(SummonerSpells).get(
                    participant['spell1Id']).toJSon(self.language),
                "spell2":
                session.query(SummonerSpells).get(
                    participant['spell2Id']).toJSon(self.language),
                "team":
                participant['teamId']
            }
            participants.append(participant_data)

        current_game['participants'] = participants

        return current_game
Пример #5
0
    def get_summoner_league(self, summoner_id):
        """
        given a summoner id, return the following data

        {
            "queueType": "RANKED_FLEX_SR",
            "hotStreak": false,
            "wins": 5,
            "veteran": false,
            "losses": 7,
            "playerOrTeamId": "89028317",
            "tier": "BRONZE",
            "playerOrTeamName": "EspinoKiller",
            "inactive": false,
            "rank": "II",
            "freshBlood": false,
            "leagueName": "Cho'Gath's Mercenaries",
            "leaguePoints": 0
        }
        :param summoner_id: the summoner id of a player, found in the returned data of get_summoner_info(summoner_name)
        :return a list of dictionaries with the leagues info
        """
        league_info = get_response(
            BASE_URL.format(self.platform) +
            'league/v3/positions/by-summoner/%s' % summoner_id)
        leagues = []
        for league in league_info:
            data = {
                'league': league['queueType'],
                'tier': league['tier'],
                'rank': league['rank'],
                'hotStreak': league['hotStreak'],
                'freshBlood': league['freshBlood'],
                'veteran': league['veteran'],
                'wins': league['wins'],
                'losses': league['losses'],
                'points': league['leaguePoints']
            }
            leagues.append(data)

        return leagues
Пример #6
0
    def get_summoner_recent_rankeds(self, account_id):
        """
        given an account id, return the following data
        "matches": [
            {
                "lane": "TOP",
                "gameId": 3258236269,
                "champion": 106,
                "platformId": "EUW1",
                "timestamp": 1499692802391,
                "queue": 420,
                "role": "SOLO",
                "season": 9
            },
        "endIndex": 20,
        "startIndex": 0,
        "totalGames": 1568

        :param account_id: the account id of a summoner, found in the returned data of get_summoner_info(summoner_name)
        :return: a list of dictionaries with info about the last 20 games of a summoner
        """

        recent_games_info = get_response(
            BASE_URL.format(self.platform) +
            'match/v3/matchlists/by-account/%s?endIndex=20&beginIndex=0' %
            account_id)['matches']
        recent_games = []
        for game in recent_games_info:
            data = {
                'lane': game['lane'],
                'gameId': game['gameId'],
                'championId': game['champion'],
                'queue': game['queue'],
                'season': game['season']
            }
            recent_games.append(data)

        return recent_games
Пример #7
0
    def get_summoner_recent_matches(self, account_id):
        """
        given an account id, return the following data

         "matches": [
            {
                "lane": "MID",
                "gameId": 3265138942,
                "champion": 50,
                "platformId": "EUW1",
                "timestamp": 1500130368205,
                "queue": 65,
                "role": "NONE",
                "season": 9
            },
        "endIndex": 20,
        "startIndex": 0,
        "totalGames": 20

        :param account_id: the account id of a summoner, found in the returned data of get_summoner_info(summoner_name)
        :return: a list of dictionaries with info about the last 20 games of a summoner
        """

        recent_games_info = get_response(
            BASE_URL.format(self.platform) +
            'match/v3/matchlists/by-account/%s/recent' % account_id)['matches']
        recent_games = []
        for game in recent_games_info:
            data = {
                'lane': game['lane'],
                'gameId': game['gameId'],
                'championId': game['champion'],
                'queue': game['queue'],
                'season': game['season']
            }
            recent_games.append(data)

        return recent_games
Пример #8
0
    def get_summoner_top_champions(self, summoner_id):
        """
        given a summoner id, return the following data 5 times
        {
            "championLevel": 7,
            "chestGranted": true,
            "championPoints": 167601,
            "championPointsSinceLastLevel": 146001,
            "playerId": 23880012,
            "championPointsUntilNextLevel": 0,
            "tokensEarned": 0,
            "championId": 119,
            "lastPlayTime": 1497895907000
        }

        :param summoner_id: the summoner id of a player, found in the returned data of get_summoner_info(summoner_name)
        :return: a list of dictionaries with the info of the player's top champions
        """
        top_champions_info = get_response(
            BASE_URL.format(self.platform) +
            'champion-mastery/v3/champion-masteries/by-summoner/%s' %
            summoner_id)
        top_champions = []
        for i in range(5):
            champion = top_champions_info[i]
            extra_info = session.query(Champions).get(champion['championId'])
            data = {
                'lvl': champion['championLevel'],
                'points': champion['championPoints'],
            }
            total_info = {
                **data, "name": extra_info.name,
                "title": extra_info.get_title(self.language),
                "image": CHAMPIONS_SPLASH_URL.format(extra_info.champ_key, 0)
            }
            top_champions.append(total_info)

        return top_champions