def process_structure_node(curs, curs_list, filename, parent, struct): section = None if struct.has_key('file'): print struct['file'] jsonfile = os.path.dirname(filename) + "/" + struct['file'] fp = open(jsonfile, 'r') data = json.load(fp) fp.close() section_id = insert_section(curs, curs_list, parent['section_id'], data) fetch_section(curs, section_id) section = curs.fetchone() else: find_section(curs, name=struct['name'], parent_id=parent['section_id']) section = curs.fetchone() if not section: section_id = append_child_section( curs, parent['section_id'], 'list', None, struct['name'], None, 'PFSRD', None, None, None, None, generate_url(curs, parent['section_id'], struct['name'], create_index=struct.get('create_index', True), parent_url=parent['url']), False) fetch_section(curs, section_id) section = curs.fetchone() for child in struct.get('children', []): process_structure_node(curs, curs_list, filename, section, child)
def insert_section(curs, curs_list, parent_id, section): if section['type'] == 'spell_list': add_spell_list(curs, curs_list, section) else: sec_id = append_child_section(curs, parent_id, section['type'], section.get('subtype'), section.get('name'), section.get('abbrev'), section.get('source'), section.get('description'), section.get('text'), section.get('image'), section.get('alt'), generate_url(curs, parent_id, section.get('name'), create_index=section.get('create_index', True)), section.get('create_index')) section['section_id'] = sec_id insert_subrecords(curs, curs_list, section, sec_id) for s in section.get('sections', []): insert_section(curs, curs_list, sec_id, s) return sec_id
def insert_section(curs, parent_id, section): if section['type'] == 'spell_list': add_spell_list(curs, section) else: sec_id = append_child_section(curs, parent_id, section['type'], section.get('subtype'), section.get('name'), section.get('abbrev'), section.get('source'), section.get('description'), section.get('text')) section['section_id'] = sec_id insert_subrecords(curs, section, sec_id) for s in section.get('sections', []): insert_section(curs, sec_id, s) return sec_id
def insert_section(curs, parent_id, section): sec_id = append_child_section(curs, parent_id, section['type'], section.get('name'), section.get('abbrev'), section.get('source'), section.get('description'), section.get('text'), section.get('image'), section.get('alt'), section.get('url'), section.get('create_index')) section['section_id'] = sec_id for s in section.get('sections', []): insert_section(curs, sec_id, s) return sec_id
def fetch_parent(curs, parent_name): if not parent_name: return fetch_top(curs) else: find_section(curs, name=parent_name, type='list') parent = curs.fetchone() if parent: return parent else: top = fetch_top(curs) section_id = append_child_section(curs, top['section_id'], 'list', None, parent_name, None, 'PFSRD', None, None) fetch_section(curs, section_id) return curs.fetchone()
def fetch_parent(curs, parent_name, source_name): if not parent_name: fetch_top(curs) return curs.fetchone() else: find_section(curs, name=parent_name, type='list') parent = curs.fetchone() if parent: return parent else: fetch_top(curs) top = curs.fetchone() section_id = append_child_section(curs, top['section_id'], 'list', None, parent_name, None, source_name, None, None, None, None, generate_url(curs, top['section_id'], parent_name), False) fetch_section(curs, section_id) return curs.fetchone()
def process_structure_node(curs, filename, parent, struct): section = None if struct.has_key('file'): jsonfile = os.path.dirname(filename) + "/" + struct['file'] fp = open(jsonfile, 'r') data = json.load(fp) fp.close() section_id = insert_section(curs, parent['section_id'], data) fetch_section(curs, section_id) section = curs.fetchone() else: find_section(curs, name=struct['name'], parent_id=parent['section_id']) section = curs.fetchone() if not section: section_id = append_child_section(curs, parent['section_id'], 'list', None, struct['name'], None, 'PFSRD', None, None) fetch_section(curs, section_id) section = curs.fetchone() for child in struct.get('children', []): process_structure_node(curs, filename, section, child)
def insert_section(curs, parent_id, section): sec_id = append_child_section(curs, parent_id, section['type'], section.get('name'), section.get('abbrev'), section.get('source'), section.get('description'), section.get('text')) section['section_id'] = sec_id for s in section.get('sections', []): insert_section(curs, sec_id, s) return sec_id