aboutsummaryrefslogtreecommitdiff
path: root/parser/scrapeToJson.py
diff options
context:
space:
mode:
Diffstat (limited to 'parser/scrapeToJson.py')
-rwxr-xr-xparser/scrapeToJson.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/parser/scrapeToJson.py b/parser/scrapeToJson.py
index 3310f2d..fd8403d 100755
--- a/parser/scrapeToJson.py
+++ b/parser/scrapeToJson.py
@@ -75,7 +75,7 @@ def processMonster(data, weapons, armors, spells):
bonus = armorDict['ac']
typ = armorDict['armor_type']
#desc['inventory'].append(armorDict)
- desc['inventory'].append({'name': a, 'type': 'armor', 'text': '{} armor'.format(a)})
+ desc['inventory'].append({'entry': 'item', 'name': a, 'type': 'armor', 'text': '{} armor'.format(a)})
break
if not found:
print('Cound not identify armor: {}'.format(a))
@@ -141,6 +141,7 @@ def processMonster(data, weapons, armors, spells):
desc['saves'].append(ability)
for action in desc['features']:
if re.match('.*Attack:', action['text']):
+ action['type'] = 'attack'
#toHit = int(re.search('\+(\d+) to hit', action['text']).group(1))
#selectedAbility = None
#for ability in ['str', 'dex', 'int', 'wis', 'cha', 'con']:
@@ -191,16 +192,20 @@ def processMonster(data, weapons, armors, spells):
else:
details['damage'].append(toAppend)
details['text'] = re.search('(?s)(_Hit:_ (?:\d+ [^\.]*\.)?)(.*)', action['text']).group(2).strip()
- if len(details['damage']) == 0:
- details['damage'].append({'dmg_die_count': 0, 'dmg_die_sides': 0, 'dmg_type': '-'})
+ # We may need to move some parts of the name to the text
+ if '(' in action['name']:
+ details['text'] = '(' + '('.join(action['name'].split('(')[1:]) + " " + details['text']
+ action['name'] = action['name'].split('(')[0].strip()
+ if action['name'][-1] == '.' or action['name'][-1] == ':':
+ action['name'] = action['name'][:-1].strip()
action['attack'] = {}
- for name, value in utils.formatWeapon(action['name'], details['range'][0], details['range'][1], details['reach'], details['damage'][0]['dmg_type'], details['damage'][0]['dmg_die_count'], details['damage'][0]['dmg_die_sides'], action['text']).items():
+ for name, value in utils.formatWeapon(action['name'], details['range'][0], details['range'][1], details['reach'], details['damage'], details['text']).items():
action['attack'][name] = value
if action['attack']['weapon_type'] != 'unknown':
#desc['inventory'].append(action['attack'])
- desc['inventory'].append({'name': action['attack']['name'], 'type': 'weapon', 'text': action['text']})
+ desc['inventory'].append({'entry': 'item', 'name': action['attack']['name'], 'type': 'weapons', 'text': action['text']})
elif 'spellcasting' in action['name']:
- action['type'] = 'spellcasting'
+ action['type'] = 'spells'
#print('{} has spellcasting!'.format(desc['name']))
abilities = ['Intelligence', 'Wisdom', 'Charisma']
for ability in abilities:
@@ -281,14 +286,14 @@ def dumpStuff(stuff, destDir):
with open(destDir + '/' + thing['name'].replace(' ', '_').replace('/', '') + '.json', 'w') as f:
json.dump(thing, f, indent=2)
-dumpStuff(weapons, 'parsed/items/weapons/')
-dumpStuff(armors, 'parsed/items/armor/')
+dumpStuff(weapons, 'parsed/weapons/')
+dumpStuff(armors, 'parsed/armor/')
dumpStuff(spells, 'parsed/spells/')
for monster in Path(utils.docsLoc + '/gamemaster_rules/monsters/').glob('*.md'):
#print('Processing {}'.format(monster))
with monster.open() as f:
data = f.read()
- Path('parsed/monsters/').mkdir(exist_ok=True)
- with open('parsed/monsters/' + monster.stem + '.json', 'w') as f:
+ Path('parsed/creatures/').mkdir(exist_ok=True)
+ with open('parsed/creatures/' + monster.stem + '.json', 'w') as f:
json.dump(processMonster(data, weapons, armors, spells), f, indent=2)