From 798aa87602bcef68a0dcf3574caa35099dd4580f Mon Sep 17 00:00:00 2001 From: James Miller Date: Mon, 24 Feb 2020 21:18:13 -0600 Subject: [PATCH] ammo sql -> yaml implemented; related to #59 --- data/yaml/ammunition.yaml | 43 ++++++++++++++++ .../yaml/deprecated/tmp-ammunition-to-yaml.py | 50 +++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 data/yaml/ammunition.yaml create mode 100644 data/yaml/deprecated/tmp-ammunition-to-yaml.py diff --git a/data/yaml/ammunition.yaml b/data/yaml/ammunition.yaml new file mode 100644 index 0000000..94f8a35 --- /dev/null +++ b/data/yaml/ammunition.yaml @@ -0,0 +1,43 @@ +ammunition: +- amount: 10 + bulk: 0.1 + descr: These projectiles are the ammunition for bows. The shaft of an arrow is made + of wood. It is stabilized in flight by fletching at one end and bears a metal + head on the other. + name: Arrows + price_gp: 0.1 + source: + - abbr: CRB + page_start: 282 + page_stop: 282 +- amount: 10 + bulk: 0.1 + descr: These thin, light darts are typically made of hardwood and stabilized with + fletching of down or fur. They are often hollow so they can be used to deliver + poison. + name: Blowgun Darts + price_gp: 0.05 + source: + - abbr: CRB + page_start: 281 + page_stop: 281 +- amount: 10 + bulk: 0.1 + descr: Shorter than traditional arrows but similar in construction, bolts are the + ammunition used by crossbows. + name: Bolts + price_gp: 0.1 + source: + - abbr: CRB + page_start: 281 + page_stop: 281 +- amount: 10 + bulk: 0.1 + descr: These are small metal balls, typically either iron or lead, designed to be + used as ammunition in slings. + name: Sling Bullets + price_gp: 0.01 + source: + - abbr: CRB + page_start: 281 + page_stop: 281 diff --git a/data/yaml/deprecated/tmp-ammunition-to-yaml.py b/data/yaml/deprecated/tmp-ammunition-to-yaml.py new file mode 100644 index 0000000..519b9b8 --- /dev/null +++ b/data/yaml/deprecated/tmp-ammunition-to-yaml.py @@ -0,0 +1,50 @@ +import sqlite3 +import yaml + + +def main(): + conn = sqlite3.connect('../../pf2.db') + + conn.row_factory = sqlite3.Row + c = conn.cursor() + c.execute("select * from ammunition;") + res = [dict(row) for row in c.fetchall()] + + # for i in res: + # print(i) + + reslist = [] + for i in res: + tmp = { + "name": + i['name'], + "price_gp": + i['price_gp'], + "amount": + i['amount'], + "bulk": + i['bulk'], + "descr": + i['descr'], + "source": [ + { + 'abbr': 'CRB', + 'page_start': int(i['sources_pages']), + 'page_stop': int(i['sources_pages']) + }, + ] + } + reslist.append(tmp) + + # print(reslist) + + tmpd = {'ammunition': reslist} + + # now dump to yaml + final = yaml.safe_dump(tmpd, allow_unicode=True) + with open('tmp-ammo.yaml', 'w') as f: + f.write(final) + + +if __name__ == '__main__': + main()