def add_spell_list(curs, struct): if not struct['type'] == 'spell_list': raise Exception("This should only be run on spell list files") if struct['class'] in ("Sorcerer/wizard", "Sorcerer/Wizard"): struct['class'] = "Sorcerer" add_spell_list(curs, struct) struct['class'] = "Wizard" add_spell_list(curs, struct) return struct = fix_spell_list(struct) level = struct['level'] class_name = cap_words(struct['class']) for sp in struct['spells']: name = cap_words(sp['name'].strip()) find_section(curs, name=name, type='spell') spell = curs.fetchone() if not spell: raise Exception("Cannot find spell %s" % name) fetch_spell_lists(curs, spell['section_id'], class_name=class_name) if not curs.fetchone(): magic_type = find_magic_type(class_name.lower()) insert_spell_list(curs, spell['section_id'], level, class_name, magic_type) fix_spell_level_text(curs, spell['section_id']) if sp.has_key('description'): update_section(curs, spell['section_id'], description=sp['description'])
def fix_spell_level_text(curs, section_id): fetch_spell_lists(curs, section_id) sl = [] objs = curs.fetchall() for obj in objs: sl.append(obj['class'] + ": " + str(obj['level'])) level_text = "; ".join(sl) update_spell_detail(curs, section_id, level_text=level_text)
def do_add_spell_list(curs, spell, sp, class_name, level): fetch_spell_lists(curs, spell['section_id'], class_name=class_name) if not curs.fetchone(): magic_type = find_magic_type(class_name.lower()) insert_spell_list(curs, spell['section_id'], level, class_name, magic_type) fix_spell_level_text(curs, spell['section_id']) if sp.has_key('description') and sp['description'] != '': update_section(curs, spell['section_id'], description=sp['description'])
def do_add_spell_list(curs, spell, sp, class_name, level): fetch_spell_lists(curs, spell['section_id'], class_name=class_name) if not curs.fetchone(): magic_type = find_magic_type(class_name.lower()) insert_spell_list(curs, spell['section_id'], level, class_name, magic_type) fix_spell_level_text(curs, spell['section_id']) if sp.has_key('description'): update_section(curs, spell['section_id'], description=sp['description'])
def do_add_spell_list(curs, spell, description, type, name, level, notes): fetch_spell_lists(curs, spell['section_id'], type=type, name=name) if not curs.fetchone(): magic_type = "divine" if type == "class": magic_type = find_magic_type(name.lower()) insert_spell_list(curs, spell['section_id'], level, type, name, notes, magic_type) fix_spell_list_text(curs, spell['section_id'], type) if description: update_section(curs, spell['section_id'], description=description)
def fix_spell_list_text(curs, section_id, type): fetch_spell_lists(curs, section_id, type=type) sl = [] objs = curs.fetchall() for obj in objs: sl.append(obj['name'] + ": " + str(obj['level'])) list_text = "; ".join(sl) if type == "class": update_spell_detail(curs, section_id, level_text=list_text) elif type == "domain": update_spell_detail(curs, section_id, domain_text=list_text)
def handle_spell(conn, section): curs = conn.cursor() try: fetch_spell_detail(curs, section['section_id']) detail = curs.fetchone() if detail: del detail['spell_detail_id'] del detail['section_id'] section.update(detail) fetch_spell_lists(curs, section['section_id']) levels = [] for level in curs.fetchall(): levels.append({ "type": level["type"], "name": level['name'], "notes": level['notes'], "level": level['level'] }) if len(levels) > 0: section['levels'] = levels fetch_spell_subschools(curs, section['section_id']) subschools = [] for subschool in curs.fetchall(): subschools.append(subschool['subschool']) if len(subschools) > 0: section['subschool'] = subschools fetch_spell_descriptors(curs, section['section_id']) descriptors = [] for descriptor in curs.fetchall(): descriptors.append(descriptor['descriptor']) if len(descriptors) > 0: section['descriptor'] = descriptors fetch_spell_effects(curs, section['section_id']) effects = [] for effect in curs.fetchall(): effects.append({ 'name': effect['name'], 'text': effect['description'] }) if len(effects) > 0: section['effects'] = effects fetch_spell_components(curs, section['section_id']) components = [] for component in curs.fetchall(): c = {"type": component['component_type']} if component['description']: c['text'] = component['description'] components.append(c) if len(components) > 0: section['components'] = components finally: curs.close()
def handle_spell(curs, source_curs, index_id, section_id): fetch_spell_lists(source_curs, section_id) for spell_list in source_curs.fetchall(): insert_spell_list_index(curs, index_id, spell_list['level'], spell_list['class'], spell_list['magic_type']) fetch_spell_descriptors(source_curs, section_id) for spell_descriptor in source_curs.fetchall(): insert_spell_descriptor_index(curs, index_id, spell_descriptor['descriptor']) fetch_spell_components(source_curs, section_id) for spell_component in source_curs.fetchall(): insert_spell_component_index(curs, index_id, spell_component['component_type']) fetch_spell_subschools(source_curs, section_id) for spell_subschool in source_curs.fetchall(): insert_spell_subschool_index(curs, index_id, spell_subschool['subschool'])
def handle_spell(conn, section): curs = conn.cursor() try: fetch_spell_detail(curs, section['section_id']) detail = curs.fetchone() if detail: del detail['spell_detail_id'] del detail['section_id'] section.update(detail) fetch_spell_lists(curs, section['section_id']) levels = [] for level in curs.fetchall(): levels.append({"type": level["type"], "name": level['name'], "notes": level['notes'], "level": level['level']}) if len(levels) > 0: section['levels'] = levels fetch_spell_subschools(curs, section['section_id']) subschools = [] for subschool in curs.fetchall(): subschools.append(subschool['subschool']) if len(subschools) > 0: section['subschool'] = subschools fetch_spell_descriptors(curs, section['section_id']) descriptors = [] for descriptor in curs.fetchall(): descriptors.append(descriptor['descriptor']) if len(descriptors) > 0: section['descriptor'] = descriptors fetch_spell_effects(curs, section['section_id']) effects = [] for effect in curs.fetchall(): effects.append({'name': effect['name'], 'text': effect['description']}) if len(effects) > 0: section['effects'] = effects fetch_spell_components(curs, section['section_id']) components = [] for component in curs.fetchall(): c = {"type": component['component_type']} if component['description']: c['text'] = component['description'] components.append(c) if len(components) > 0: section['components'] = components finally: curs.close()