-convert price_gp to price_cp in weapons

bradl/monsters-adult-gold-dragon
James Ryland Miller 2020-04-23 16:06:45 -05:00
parent 00685eb77c
commit ee57fd402a
1 changed files with 18 additions and 2 deletions

View File

@ -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()
main()