From 92d885ddb5c82841783166c2c4c6447aee5ff698 Mon Sep 17 00:00:00 2001 From: James Miller Date: Thu, 23 Apr 2020 17:00:39 -0500 Subject: [PATCH] weaponst able imported, still need to link weapons to traits --- data/yaml/tmp-sql-to-weapons.py | 163 ++++++++++++++++++-------------- 1 file changed, 93 insertions(+), 70 deletions(-) diff --git a/data/yaml/tmp-sql-to-weapons.py b/data/yaml/tmp-sql-to-weapons.py index bb04827..cf483be 100644 --- a/data/yaml/tmp-sql-to-weapons.py +++ b/data/yaml/tmp-sql-to-weapons.py @@ -3,92 +3,115 @@ import yaml import pprint def main(): - pp = pprint.PrettyPrinter(indent=4) + pp = pprint.PrettyPrinter(indent=4, width=160) conn = sqlite3.connect('../../pf2.db') conn.row_factory = sqlite3.Row - # DO WEAPON GROUPS + + # DO WEAPONS q = """ SELECT - sources_pages, - name, - descr - FROM weapongroups + price_gp, + dice_size, + bulk, + hands, + range, + reload, + weapons.name, + weapons.descr, + weapons.sources_id, + weapons.sources_pages, + weaponcategories.name AS weaponcategory, + weapongroups.name AS weapongroup, + damagetypes.name AS damagetype + FROM weapons + INNER JOIN + weaponcategories ON weapons.weaponcategories_id = weaponcategories.weaponcategories_id + INNER JOIN + weapongroups ON weapons.weapongroups_id = weapongroups.weapongroups_id + INNER JOIN + damagetypes ON weapons.damagetypes_id = damagetypes.damagetypes_id + ; """ c = conn.cursor() c.execute(q) data = [dict(row) for row in c.fetchall()] + for i in data: + # handle empty bulk entries to match the abbr field in bulks.yaml + if i['bulk'] == '': + i['bulk'] = '-' + # convert gp prices to cp prices to avoid float issues + if i['price_gp'] == '': + i['price_gp'] = '0' + i['price_cp'] = int(float(i['price_gp']) * 100) + del i['price_gp'] + i['source'] = [ + { + 'abbr': 'CRB', + 'page_start': int(i['sources_pages']), + 'page_stop': int(i['sources_pages']) + } + ] + del i['sources_id'] + del i['sources_pages'] + + pp.pprint(data) - # "source": [ - # { - # 'abbr': 'CRB', - # 'page_start': int(i['sources_pages']), - # 'page_stop': int(i['sources_pages']) - # }, - - wgdata = [] - for i in data: - res = { - 'name': i['name'], - 'descr': i['descr'], - 'source': [ - { - 'abbr': 'CRB', - 'page_start': int(i['sources_pages']), - 'page_stop': int(i['sources_pages']) - } - ] - } - wgdata.append(res) - - pp.pprint(wgdata) - finalwgdata = {'weapongroups': wgdata} - pp.pprint(finalwgdata) - - final = yaml.safe_dump(finalwgdata, allow_unicode=True) - with open('tmp-weapongroups.yaml', 'w') as f: + fdata = {'weapons': data} + final = yaml.safe_dump(fdata, allow_unicode=True) + with open('tmp-weapons.yaml', 'w') as f: f.write(final) - # DO WEAPONS - - # q = """ - # SELECT - # price_gp, - # dice_size, - # bulk, - # hands, - # range, - # reload, - # name, - # descr, - # (SELECT name FROM actions) as action_name -- use this as template for subqueries - # FROM weapons; - # """ - - # c = conn.cursor() - # c.execute(q) - # data = [dict(row) for row in c.fetchall()] - # for i in data: - # # handle empty bulk entries to match the abbr field in bulks.yaml - # if i['bulk'] == '': - # i['bulk'] = '-' - # # convert gp prices to cp prices to avoid float issues - # if i['price_gp'] == '': - # i['price_gp'] = '0' - # i['price_cp'] = int(float(i['price_gp']) * 100) - # del i['price_gp'] - - # pp.pprint(data) - - # fdata = {'weapons': data} - # final = yaml.safe_dump(fdata, allow_unicode=True) - # with open('tmp-weapons.yaml', 'w') as f: - # f.write(final) - if __name__ == '__main__': main() + +# def done(): + # DO WEAPON GROUPS + + # q = """ + # SELECT + # sources_pages, + # name, + # descr + # FROM weapongroups + # """ + + # c = conn.cursor() + # c.execute(q) + # data = [dict(row) for row in c.fetchall()] + # pp.pprint(data) + + # # "source": [ + # # { + # # 'abbr': 'CRB', + # # 'page_start': int(i['sources_pages']), + # # 'page_stop': int(i['sources_pages']) + # # }, + + # wgdata = [] + # for i in data: + # res = { + # 'name': i['name'], + # 'descr': i['descr'], + # 'source': [ + # { + # 'abbr': 'CRB', + # 'page_start': int(i['sources_pages']), + # 'page_stop': int(i['sources_pages']) + # } + # ] + # } + # wgdata.append(res) + + # pp.pprint(wgdata) + # finalwgdata = {'weapongroups': wgdata} + # pp.pprint(finalwgdata) + + # final = yaml.safe_dump(finalwgdata, allow_unicode=True) + # with open('tmp-weapongroups.yaml', 'w') as f: + # f.write(final)