From ee57fd402a8d3ce65134e0b248429d712d1ae03e Mon Sep 17 00:00:00 2001 From: James Ryland Miller Date: Thu, 23 Apr 2020 16:06:45 -0500 Subject: [PATCH] -convert price_gp to price_cp in weapons --- data/yaml/tmp-sql-to-weapons.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/data/yaml/tmp-sql-to-weapons.py b/data/yaml/tmp-sql-to-weapons.py index b98d5d2..fa2978d 100644 --- a/data/yaml/tmp-sql-to-weapons.py +++ b/data/yaml/tmp-sql-to-weapons.py @@ -3,6 +3,7 @@ import yaml import pprint def main(): + pp = pprint.PrettyPrinter(indent=2) conn = sqlite3.connect('../../pf2.db') conn.row_factory = sqlite3.Row @@ -23,9 +24,24 @@ def main(): c = conn.cursor() c.execute(q) data = [dict(row) for row in c.fetchall()] - pprint.pprint(data) + for i in data: + # handle empty bulk entries + 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() \ No newline at end of file + main()