2020-04-22 01:52:11 -04:00
|
|
|
import sqlite3
|
|
|
|
import yaml
|
|
|
|
import pprint
|
|
|
|
|
|
|
|
def main():
|
2020-04-23 18:00:39 -04:00
|
|
|
pp = pprint.PrettyPrinter(indent=4, width=160)
|
2020-04-22 01:52:11 -04:00
|
|
|
conn = sqlite3.connect('../../pf2.db')
|
|
|
|
conn.row_factory = sqlite3.Row
|
|
|
|
|
2020-04-23 18:00:39 -04:00
|
|
|
|
|
|
|
# DO WEAPONS
|
2020-04-23 17:29:38 -04:00
|
|
|
|
2020-04-22 01:52:11 -04:00
|
|
|
q = """
|
|
|
|
SELECT
|
2020-04-23 18:00:39 -04:00
|
|
|
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
|
|
|
|
;
|
2020-04-22 01:52:11 -04:00
|
|
|
"""
|
|
|
|
|
|
|
|
c = conn.cursor()
|
|
|
|
c.execute(q)
|
|
|
|
data = [dict(row) for row in c.fetchall()]
|
2020-04-23 18:00:39 -04:00
|
|
|
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']
|
2020-04-23 18:24:29 -04:00
|
|
|
# Get traits
|
|
|
|
qq = """
|
|
|
|
SELECT traits.short_name
|
|
|
|
FROM traits
|
|
|
|
INNER JOIN
|
|
|
|
weapons_traits ON traits.trait_id = weapons_traits.trait_id
|
|
|
|
INNER JOIN
|
|
|
|
weapons ON weapons.weapons_id = weapons_traits.weapons_id
|
|
|
|
WHERE weapons.weapons_id = (
|
|
|
|
SELECT weapons.weapons_id
|
|
|
|
WHERE weapons.name = ?
|
|
|
|
);
|
|
|
|
"""
|
|
|
|
cc = conn.cursor()
|
|
|
|
cc.execute(qq, (i['name'],))
|
|
|
|
res = cc.fetchall()
|
|
|
|
print("\n\nWeapon: {}".format(i['name']))
|
|
|
|
tlist = []
|
|
|
|
for j in res:
|
|
|
|
x = tuple(j)[0]
|
|
|
|
tlist.append(x)
|
|
|
|
if len(tlist) > 0:
|
|
|
|
i['traits'] = tlist
|
|
|
|
else:
|
|
|
|
i['traits'] = None
|
2020-04-23 17:29:38 -04:00
|
|
|
|
|
|
|
|
2020-04-23 18:24:29 -04:00
|
|
|
|
|
|
|
# pp.pprint(data)
|
2020-04-23 18:00:39 -04:00
|
|
|
|
|
|
|
fdata = {'weapons': data}
|
|
|
|
final = yaml.safe_dump(fdata, allow_unicode=True)
|
|
|
|
with open('tmp-weapons.yaml', 'w') as f:
|
2020-04-23 17:06:45 -04:00
|
|
|
f.write(final)
|
2020-04-22 01:52:11 -04:00
|
|
|
|
2020-04-23 18:00:39 -04:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|
|
|
|
|
|
|
|
# def done():
|
|
|
|
# DO WEAPON GROUPS
|
2020-04-23 17:29:38 -04:00
|
|
|
|
|
|
|
# q = """
|
|
|
|
# SELECT
|
2020-04-23 18:00:39 -04:00
|
|
|
# sources_pages,
|
2020-04-23 17:29:38 -04:00
|
|
|
# name,
|
2020-04-23 18:00:39 -04:00
|
|
|
# descr
|
|
|
|
# FROM weapongroups
|
2020-04-23 17:29:38 -04:00
|
|
|
# """
|
|
|
|
|
|
|
|
# c = conn.cursor()
|
|
|
|
# c.execute(q)
|
|
|
|
# data = [dict(row) for row in c.fetchall()]
|
|
|
|
# pp.pprint(data)
|
|
|
|
|
2020-04-23 18:00:39 -04:00
|
|
|
# # "source": [
|
|
|
|
# # {
|
|
|
|
# # 'abbr': 'CRB',
|
|
|
|
# # 'page_start': int(i['sources_pages']),
|
|
|
|
# # 'page_stop': int(i['sources_pages'])
|
|
|
|
# # },
|
2020-04-22 01:52:11 -04:00
|
|
|
|
2020-04-23 18:00:39 -04:00
|
|
|
# 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)
|