コード例 #1
0
def get_champion_title(champion, language):
    titledata = {
        "id_champion": champion['id'],
        "id_language": language,
        "title": champion['title']
    }
    newChampionTitle = ChampionsTitles(**titledata)
    session.add(newChampionTitle)
コード例 #2
0
def get_passive_translations(champion, language):
    translationdata = {
        "id_champion": champion['id'],
        "id_language": language,
        "name": champion['passive']['name'],
        "description": champion['passive']['sanitizedDescription']
    }
    newPassiveTranslation = PassivesTranslations(**translationdata)
    session.add(newPassiveTranslation)
コード例 #3
0
def get_skin_translation(champion, language):
    for skin in champion['skins']:
        translationdata = {
            "id_skin": skin['id'],
            "id_language": language,
            "name": skin['name']
        }
        newSkinTranslation = SkinsTranslations(**translationdata)
        session.add(newSkinTranslation)
コード例 #4
0
def get_champion_enemytips(champion, language):
    id_champion = champion['id']
    for tip in champion['enemytips']:
        tipdata = {
            "id_champion": id_champion,
            "id_language": language,
            "tip": tip
        }
        newChampionEnemyTip = ChampionEnemyTips(**tipdata)
        session.add(newChampionEnemyTip)
コード例 #5
0
def get_champion_info(champion):
    infodata = {
        "id_champion": champion['id'],
        "difficulty": champion['info']['difficulty'],
        "attack": champion['info']['attack'],
        "defense": champion['info']['defense'],
        "magic": champion['info']['magic']
    }
    newChampionInfo = ChampionsInfo(**infodata)
    session.add(newChampionInfo)
    session.commit()
コード例 #6
0
def get_champion_skins(champion, language):
    id_champion = champion['id']
    for skin in champion['skins']:
        skindata = {
            "id": skin['id'],
            "id_champion": id_champion,
            "num": skin['num']
        }
        newChampionSkin = ChampionsSkins(**skindata)
        session.add(newChampionSkin)
        session.commit()
コード例 #7
0
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)
コード例 #8
0
def get_champion_spells(champion, language):
    id_champion = champion['id']
    for spell in champion['spells']:
        spelldata = {
            "id_champion": id_champion,
            "image": spell['image']['full'],
            "spell_key": spell['key']
        }
        newChampionSpell = ChampionsSpells(**spelldata)
        session.add(newChampionSpell)
        session.commit()
コード例 #9
0
def get_champion(champion):
    championdata = {
        "id": champion['id'],
        "name": champion['name'],
        "champ_key": champion['key'],
        "rols": ','.join(champion['tags']),
        "image_champion": champion['image']['full'],
        "image_passive": champion['passive']['image']['full']
    }
    newChampion = Champions(**championdata)
    session.add(newChampion)
    session.commit()
コード例 #10
0
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()
コード例 #11
0
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()
コード例 #12
0
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()