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()