def get_spell_translations(champion, language): for spell in champion['spells']: spell_id = session.query(ChampionsSpells).filter_by(spell_key=spell['key']).one().id translationdata = { "id_spell": spell_id, "id_language": language, "name": spell['name'], "description": spell['sanitizedDescription'] } newSpellTranslation = SpellsTranslations(**translationdata) session.add(newSpellTranslation)
def main(): """ for each locale json file reads the file parsing it to json and insert the data into the database :return: None """ first_time = True for id_locale, locale in LOCALES.items(): with open("{}.json".format(locale)) as inputfile: response = json.load(inputfile) try: masteryversion = session.query(Configuration).filter_by( code="{} version".format(response['type'])).one() except: configdata = { "code": "{} version".format(response['type']), "value": response['version'] } print("añadiendo versión maestrias") masteryversion = Configuration(**configdata) session.add(masteryversion) if masteryversion.value != response['version']: masteryversion.version = response['version'] session.add(masteryversion) masteries_data = response['data'] for mastery in masteries_data.values(): # champion, champion spells, champions skins and champions info are locale independant if first_time: mastery_data = { "id": mastery['id'], "ranks": mastery['ranks'], "image": mastery['image']['full'], "tree": mastery['masteryTree'] } newMastery = Masteries(**mastery_data) session.add(newMastery) translation_data = { "id_mastery": mastery['id'], "id_language": id_locale, "name": mastery['name'], "description": ','.join(mastery['sanitizedDescription']) } newTranslation = MasteriesTranslations(**translation_data) session.add(newTranslation) first_time = False print("todos los datos insertados con éxito para {}".format(locale)) session.commit()
def main(): """ for each locale json file reads the file parsing it to json and insert the data into the database :return: None """ first_time = True for id_locale, locale in LOCALES.items(): with open("runes{}.json".format(locale)) as inputfile: response = json.load(inputfile) try: runes_version = session.query(Configuration).filter_by( code="{} version".format(response['type'])).one() except: configdata = { "code": "{} version".format(response['type']), "value": response['version'] } print("añadiendo versión runas") runes_version = Configuration(**configdata) session.add(runes_version) if runes_version.value != response['version']: runes_version.version = response['version'] session.add(runes_version) runes_data = response['data'] for runes in runes_data.values(): if first_time: data = { "id": runes['id'], "tier": runes['rune']['tier'], "type": runes['rune']['type'], "tags": ','.join(runes['tags']), "image": runes['image']['full'] } newSummSpell = Runes(**data) session.add(newSummSpell) translation = { "id_rune": runes['id'], "id_language": id_locale, "name": runes['name'], "description": runes['sanitizedDescription'] } newTranslation = RunesTranslations(**translation) session.add(newTranslation) first_time = False print("todos los datos insertados con éxito para {}".format(locale)) session.commit()
def get_champions_list(self): champion_list = [] for champion in session.query(Champions).all(): data = { "id": champion.id, "image": CHAMPIONS_SQUARE_URL.format(champion.version, champion.image_champion), "name": champion.name } champion_list.append(data) return {"champions": champion_list}
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
def main(): """ for each locale json file reads the file parsing it to json and insert the data into the database :return: None """ first_time = True for id_locale, locale in LOCALES.items(): with open("{}.json".format(locale)) as inputfile: response = json.load(inputfile) try: version = session.query(Configuration).filter_by(code="{} version".format(response['type'])).one() except: configdata = { "code": "{} version".format(response['type']), "value": response['version'] } print("añadiendo versión campeones") version = Configuration(**configdata) session.add(version) if version.value != response['version']: print("actualizando versión campeones") version.value = response['version'] session.add(version) champions_data = response['data'] for champion in champions_data.values(): #champion, champion spells, champions skins and champions info are locale independant if first_time: get_champion(champion) get_champion_spells(champion, id_locale) get_champion_skins(champion, id_locale) get_champion_info(champion) get_champion_title(champion, id_locale) get_passive_translations(champion, id_locale) get_spell_translations(champion, id_locale) get_skin_translation(champion, id_locale) get_champion_allytips(champion, id_locale) get_champion_enemytips(champion, id_locale) first_time = False print("todos los datos insertados con éxito para {}".format(locale)) session.commit()
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
def get_version(element): version = session.query(Configuration).filter_by( code=element).one_or_none().value return version
def get_champion_info(self, id_champion): return session.query(Champions).get(id_champion).toJson(self.language)