def generate(): with open("data/5e-SRD-Features.json") as read_file: query = "INSERT INTO features VALUES (NULL,%s,%s,%s,%s,%s)" data = json.load(read_file) for feature in data: parameters = [] _className = feature["class"]["name"] parameters.append(_className) parameters.append(feature["name"]) if ('level' in feature): parameters.append(feature['level']) else: parameters.append(0) desc = '' for line in feature["desc"]: desc += (line + "\n") parameters.append(desc) if (len(feature["name"]) > 45): print(feature["name"] + " " + str(len(feature["name"])) + "\n") if ('choice' in feature): parameters.append(feature["choice"]["choose"]) else: parameters.append(0) parameters = tuple(parameters) cursor.execute(query, parameters)
def generate(): with open("data/5e-SRD-Equipment-Categories.json", "r") as read_file: query = "INSERT INTO equipmentcategories VALUES(NULL,%s);" data = json.load(read_file) for eqCat in data: parameters = [] _category = eqCat["name"] parameters.append(_category) cursor.execute(query, parameters)
def generate(): with open("data/5e-SRD-Proficiencies.json", "r") as read_file: query = "INSERT INTO proficiences VALUES (NULL,%s,%s);" data = json.load(read_file) for proficiency in data: _type = proficiency['type'] _name = proficiency['name'] parameters = (_type, _name) cursor.execute(query,parameters)
def generate(): with open("data/5e-SRD-Races.json", "r") as read_file: queryRaces = "INSERT INTO races VALUES (NULL,%s,%s,%s,%s,%s,%s,%s,%s);" queryRaceAbilities = "INSERT INTO raceAbilities VALUES (NULL,%s,%s,%s,%s);" queryRaceStartingProficiency = "INSERT INTO starting_proficiences VALUES (NULL,%s,%s,%s);" data = json.load(read_file) for race in data: _idRace = race['index'] _name = race['name'] _speed = race['speed'] _alignment = race['alignment'] _age = race['age'] _size = race['size'] _size_description = race['size_description'] if "choose" in race['ability_bonus_options']: _ability_bonus_options_count = race['ability_bonus_options'][ 'choose'] else: _ability_bonus_options_count = 0 if "choose" in race['starting_proficiency_options']: _starting_proficiences_options_count = race[ 'starting_proficiency_options']['choose'] else: _starting_proficiences_options_count = 0 parameters = (_name, _speed, _alignment, _age, _size, _size_description, _ability_bonus_options_count, _starting_proficiences_options_count) cursor.execute(queryRaces, parameters) for ability_bonus in race['ability_bonuses']: _bonus = ability_bonus['bonus'] _idAbility = ability_bonus['url'].split("/")[-1] _isOptional = False parameters = (_bonus, _idRace, _idAbility, _isOptional) cursor.execute(queryRaceAbilities, parameters) if ('from' in race['ability_bonus_options']): for ability_bonus in race['ability_bonus_options']['from']: _bonus = ability_bonus['bonus'] _idAbility = ability_bonus['url'].split("/")[-1] _isOptional = True parameters = (_bonus, _idRace, _idAbility, _isOptional) cursor.execute(queryRaceAbilities, parameters) for starting_proficiency in race['starting_proficiencies']: _isOptional = False _idProficiency = starting_proficiency['url'].split("/")[-1] parameters = (_isOptional, _idRace, _idProficiency) cursor.execute(queryRaceStartingProficiency, parameters) if ('from' in race['starting_proficiency_options']): for starting_proficiency in race[ 'starting_proficiency_options']['from']: _isOptional = True _idProficiency = starting_proficiency['url'].split("/")[-1] parameters = (_isOptional, _idRace, _idProficiency) cursor.execute(queryRaceStartingProficiency, parameters)
def generate(): with open("data/5e-SRD-Languages.json", "r") as read_file: query = "INSERT INTO languages VALUES (NULL,%s,%s);" data = json.load(read_file) for language in data: parameters = [] parameters.append(language["name"]) parameters.append(language["type"]) cursor.execute(query, parameters)
def generate(): with open("data/5e-SRD-Magic-Schools.json", "r") as read_file: query = "INSERT INTO magicschools VALUES(NULL,%s, %s);" data = json.load(read_file) for magicSchools in data: parameters = [] _category = magicSchools["name"] _desc = magicSchools["desc"] parameters.append(_category) parameters.append(_desc) cursor.execute(query,parameters)
def generate(): with open("data/5e-SRD-Damage-Types.json", "r") as read_file: query = "INSERT INTO damageTypes VALUES (NULL,%s,%s);" data = json.load(read_file) for damageType in data: _name = damageType['name'] _desc = "" for line in damageType['desc']: _desc += (line + "\n") parameters = (_name, _desc) cursor.execute(query, parameters)
def generate(): with open("data/5e-SRD-Conditions.json", "r") as read_file: query = "INSERT INTO conditions VALUES (NULL,%s,%s);" data = json.load(read_file) for condition in data: parameters = [] desc = "" parameters.append(condition["name"]) for line in condition["desc"]: desc += (line + "\n") parameters.append(desc) parameters = tuple(parameters) cursor.execute(query, parameters)
def generate(): with open("data/5e-SRD-Traits.json", "r") as read_file: query = "INSERT INTO traits VALUES(NULL,%s, %s);" data = json.load(read_file) for traits in data: parameters = [] _name = traits["name"] _desc = "" for desc in traits["desc"]: _desc = _desc + desc parameters.append(_name) parameters.append(_desc) cursor.execute(query, parameters)
def generate(): with open("data/5e-SRD-Skills.json", "r") as read_file: query = "INSERT INTO skills VALUES (%s, NULL,%s,%s);" data = json.load(read_file) for skill in data: _name = skill["name"] print(_name) _desc = "" for desc in skill["desc"]: _desc += desc _api = skill["ability_score"]["url"].split("/")[-1] parameters = (_name, _desc, _api) cursor.execute(query, parameters)
def generate(): with open("data/5e-SRD-Ability-Scores.json", "r") as read_file: query = "INSERT INTO abilities VALUES (NULL,%s,%s,%s);" data = json.load(read_file) for proficiency in data: parameters = [] parameters.append(proficiency['name']) parameters.append(proficiency['full_name']) desc = "" for line in proficiency['desc']: desc += (line + "\n") parameters.append(desc) parameters = tuple(parameters) cursor.execute(query, parameters)
def create(): with open("tables.txt", "r") as read_file: data = read_file.read() for query in data.split(';'): if (query != ''): final_query = query + ';' lines = final_query.split('\n') for line in lines: result = re.search("CREATE TABLE `(.*)`", line) if (result != None): tableName = result.group(1) dropQuery = "DROP TABLE IF EXISTS " + tableName + ";" cursor.execute(dropQuery) cursor.execute(final_query)
def generate(): with open("data/5e-SRD-Classes.json", "r") as read_file: queryClasses = "INSERT INTO classes VALUES (NULL,%s,%s,%s);" queryClassProficiences = "INSERT INTO classproficiencies VALUES (NULL,%s,%s,%s);" queryClassSavingThrows = "INSERT INTO classsavingthrows VALUES (NULL,%s,%s);" queryClassSubclasses = "INSERT INTO classsubclasses VALUES (NULL,%s,%s);" data = json.load(read_file) for c in data: _idClass = c['index'] _name = c['name'] _hitDie = c['hit_die'] if ("choose" in c['proficiency_choices'][0]): _proficiencyChoicesCount = c['proficiency_choices'][0][ 'choose'] else: _proficiencyChoicesCount = 0 parameters = (_name, _hitDie, _proficiencyChoicesCount) cursor.execute(queryClasses, parameters) #------------proficiencies-------------- if ('from' in c['proficiency_choices'][0]): for proficiency in c['proficiency_choices'][0]['from']: _idProficiency = proficiency['url'].split("/")[-1] _isOptional = True parameters = (_idClass, _idProficiency, _isOptional) cursor.execute(queryClassProficiences, parameters) for proficiency in c['proficiencies']: _idProficiency = proficiency['url'].split("/")[-1] _isOptional = False parameters = (_idClass, _idProficiency, _isOptional) cursor.execute(queryClassProficiences, parameters) #--------------saving throw------------------------- for savingThrow in c['saving_throws']: _idAbility = savingThrow['url'].split("/")[-1] parameters = (_idClass, _idAbility) cursor.execute(queryClassSavingThrows, parameters) #-----------starting equipment------------------------- #TODO dodać parsowanie starting equipment z classes.json #-----------subclasses-------------------------- if ('subclasses' in c): for subclass in c['subclasses']: _className = subclass['name'] parameters = (_idClass, _className) cursor.execute(queryClassSubclasses, parameters)
def generate(): with open("data/5e-SRD-Spellcasting.json", "r") as read_file: query = "INSERT INTO spellcasting VALUES (NULL,%s,%s,%s,%s);" data = json.load(read_file) for spellcasting in data: if ('level' in spellcasting): _level = spellcasting['level'] else: _level = 0 _spellcastingAbilityID = spellcasting['spellcasting_ability'][ 'url'].split("/")[-1] _infos = "" for info in spellcasting['info']: _infos += "<" + info['name'] + ">\n" for line in info['desc']: _infos += (line + "\n") _idClass = spellcasting['class']['url'].split("/")[-1] parameters = (_level, _spellcastingAbilityID, _infos, _idClass) cursor.execute(query, parameters)
def generate(): with open("data/5e-SRD-Subclasses.json", "r") as read_file: querySubclasses = "INSERT INTO subclasses VALUES (%s,NULL,%s,%s,%s);" querySubclassFeatures = "INSERT INTO subclassfeatures VALUES (NULL, %s, %s);" data = json.load(read_file) for subclass in data: _className = subclass['class']['name'] _name = subclass['name'] _subclassFlavor = subclass['subclass_flavor'] _desc = "" for line in subclass['desc']: _desc += (line + "\n") parameters = (_className, _name, _subclassFlavor, _desc) cursor.execute(querySubclasses, parameters) #------------features-------------- for feature in subclass['features']: _idFeature = feature['url'].split("/")[-1] parameters = (_className, _idFeature) cursor.execute(querySubclassFeatures, parameters)
def generate(): with open("data/5e-SRD-Spells.json", "r") as read_file: querySpells = "INSERT INTO spells VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);" querySpellsSubclasses = "INSERT INTO spellsubclasses VALUES (NULL,%s,%s);" querySpellClasses = "INSERT INTO spellclasses VALUES (NULL,%s,%s);" data = json.load(read_file) for spell in data: ## WITHOUT TABLES _idSpell = spell['index'] _name = spell['name'] _page = spell['page'] _ritual = spell['ritual'] _duration = spell['duration'] _concentration = spell['concentration'] if "material" in spell: _material = spell['material'] else: _material = "" _castingTime = spell['casting_time'] _lvl = spell['level'] _range = spell['range'] # WITH TABLES fullDescription = "" diceFromDescription = "" for desc in spell['desc']: fullDescription += desc _fullDesc = fullDescription _diceFromDescription = diceFromDesc(fullDescription) fileDmgTypes = open("data//5e-SRD-Damage-Types.json", "r") parsedDMGtypes = json.load(fileDmgTypes) dmgTypes = ["heal", "healing", "healed", "regains"] for dmgType in parsedDMGtypes: dmgTypeLowerCase = dmgType["name"] dmgTypes.append(dmgTypeLowerCase.lower()) _dmgType = retriveDmgType(fullDescription, dmgTypes) ## if _diceFromDescription != None: ## print(_name + " : " + _diceFromDescription) ## if _diceFromDescription != None and _dmgType != None: ## print(_name + " : " + _diceFromDescription + " : " + _dmgType) _higherLvL = "" if "higher_level" in spell: for desc in spell['higher_level']: _higherLvL += desc _components = "" for comp in spell["components"]: _components += comp _idSchool = spell["school"]["url"].split('/')[-1] for subclass in spell["subclasses"]: _idSubclass = subclass["url"].split('/')[-1] print(_idSubclass) parameter = (_idSpell, _idSubclass) cursor.execute(querySpellsSubclasses, parameter) for classs in spell["classes"]: _idClass = classs["url"].split('/')[-1] parameter = (_idSpell, _idClass) cursor.execute(querySpellClasses, parameter) parameter = (_name, _fullDesc, _diceFromDescription, _dmgType, _higherLvL, _page, _range, _components, _material, _ritual, _duration, _concentration, _castingTime, _lvl, _idSchool) cursor.execute(querySpells, parameter)
def generate(): with open("data/5e-SRD-Subraces.json", "r") as read_file: querySubraces = "INSERT INTO subraces VALUES (NULL, %s, %s, %s, %s);" querySubraceTraits = "INSERT INTO subracetraits VALUES (NULL, %s, %s, %s);" querySubraceAbilities = "INSERT INTO subraceabilities VALUES (NULL, %s, %s, %s, %s);" querySubraceStartingProficiences = "INSERT INTO subracestartingproficiences VALUES (NULL, %s, %s, %s);" queryRaceSubraces = "INSERT INTO racesubraces VALUES (NULL, %s, %s);" data = json.load(read_file) for subrace in data: # SUBRACES parameters = [] _idSubrace = subrace["index"] parameters.append(_idSubrace) parameters.append(subrace["desc"]) if "choose" in subrace["racial_trait_options"]: parameters.append(subrace["racial_trait_options"]["choose"]) else: parameters.append(0) if "choose" in subrace["starting_proficiency_options"]: parameters.append( subrace["starting_proficiency_options"]["choose"]) else: parameters.append(0) cursor.execute(querySubraces, parameters) # RACIAL TRAITS for trait in subrace["racial_traits"]: parameters = [] parameters.append(False) parameters.append(_idSubrace) _idTrait = trait["url"].split("/")[-1] parameters.append(_idTrait) cursor.execute(querySubraceTraits, parameters) if "from" in subrace["racial_trait_options"]: for trait in subrace["racial_trait_options"]["from"]: parameters = [] parameters.append(True) parameters.append(_idSubrace) _idTrait = trait["url"].split("/")[-1] parameters.append(_idTrait) cursor.execute(querySubraceTraits, parameters) # ABILITY BONUSES for ability in subrace["ability_bonuses"]: parameters = [] parameters.append(ability["bonus"]) parameters.append(False) parameters.append(_idSubrace) _idAbility = ability["url"].split("/")[-1] parameters.append(_idAbility) cursor.execute(querySubraceAbilities, parameters) if "ability_bonus_options" in subrace: if "from" in subrace["ability_bonus_options"]: for ability in subrace["ability_bonus_options"]["from"]: parameters = [] parameters.append(ability["bonus"]) parameters.append(True) parameters.append(_idSubrace) _idAbility = ability["url"].split("/")[-1] parameters.append(_idAbility) cursor.execute(querySubraceAbilities, parameters) # STARTING PROFICIENCIES for proficiency in subrace["starting_proficiencies"]: parameters = [] parameters.append(False) _idProficiency = proficiency["url"].split("/")[-1] parameters.append(_idProficiency) parameters.append(_idSubrace) cursor.execute(querySubraceStartingProficiences, parameters) if "from" in subrace["starting_proficiency_options"]: for proficiency in subrace["starting_proficiency_options"][ "from"]: parameters = [] parameters.append(True) _idProficiency = proficiency["url"].split("/")[-1] parameters.append(_idProficiency) parameters.append(_idSubrace) cursor.execute(querySubraceStartingProficiences, parameters) # RACE SUBRACES parameters = [] _idRace = subrace["race"]["url"].split("/")[-1] parameters.append(_idRace) parameters.append(_idSubrace) cursor.execute(queryRaceSubraces, parameters)
def generate(): with open("data/5e-SRD-Levels.json", "r") as read_file: queryFeatures = "INSERT INTO levels VALUES (%s,NULL,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);" queryLevelFeatures = "INSERT INTO levelfeatures VALUES (NULL,%s,%s);" data = json.load(read_file) for level in data: _className = level['class']['name'] if ('level' in level): _level = level['level'] else: _level = 0 if ('ability_score_bonuses' in level): _abilityScoreBonuses = level['ability_score_bonuses'] else: _abilityScoreBonuses = 0 if ('prof_bonus' in level): _profBonus = level['prof_bonus'] else: _profBonus = 0 if ('spellcasting' in level): sc = level['spellcasting'] if ('cantrips_known' in sc): cantrips_known = sc['cantrips_known'] else: cantrips_known = 0 if ('spells_known' in sc): spells_known = sc['spells_known'] else: spells_known = 0 if ('spell_slots_level_1' in sc): spell_slots_level_1 = sc['spell_slots_level_1'] else: spell_slots_level_1 = 0 if ('spell_slots_level_2' in sc): spell_slots_level_2 = sc['spell_slots_level_2'] else: spell_slots_level_2 = 0 if ('spell_slots_level_3' in sc): spell_slots_level_3 = sc['spell_slots_level_3'] else: spell_slots_level_3 = 0 if ('spell_slots_level_3' in sc): spell_slots_level_3 = sc['spell_slots_level_3'] else: spell_slots_level_3 = 0 if ('spell_slots_level_4' in sc): spell_slots_level_4 = sc['spell_slots_level_4'] else: spell_slots_level_4 = 0 if ('spell_slots_level_5' in sc): spell_slots_level_5 = sc['spell_slots_level_5'] else: spell_slots_level_5 = 0 if ('spell_slots_level_6' in sc): spell_slots_level_6 = sc['spell_slots_level_6'] else: spell_slots_level_6 = 0 if ('spell_slots_level_7' in sc): spell_slots_level_7 = sc['spell_slots_level_7'] else: spell_slots_level_7 = 0 if ('spell_slots_level_8' in sc): spell_slots_level_8 = sc['spell_slots_level_8'] else: spell_slots_level_8 = 0 if ('spell_slots_level_9' in sc): spell_slots_level_9 = sc['spell_slots_level_9'] else: spell_slots_level_9 = 0 parameters = (_className, _level, _abilityScoreBonuses, _profBonus, cantrips_known, spells_known, spell_slots_level_1, spell_slots_level_2, spell_slots_level_3, spell_slots_level_4, spell_slots_level_5, spell_slots_level_6, spell_slots_level_7, spell_slots_level_8, spell_slots_level_9) else: parameters = (_className, _level, _abilityScoreBonuses, _profBonus, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) cursor.execute(queryFeatures, parameters) for feature in level['features']: _idFeature = feature['url'].split("/")[-1] parameters = (_className, _idFeature) cursor.execute(queryLevelFeatures, parameters)