aboutsummaryrefslogtreecommitdiff
path: root/parser/scrapeToJson.py
diff options
context:
space:
mode:
Diffstat (limited to 'parser/scrapeToJson.py')
-rwxr-xr-xparser/scrapeToJson.py32
1 files changed, 16 insertions, 16 deletions
diff --git a/parser/scrapeToJson.py b/parser/scrapeToJson.py
index 0304d7b..3310f2d 100755
--- a/parser/scrapeToJson.py
+++ b/parser/scrapeToJson.py
@@ -6,7 +6,7 @@ import utils
def processMonster(data, weapons, armors, spells):
names2names = {'ac': 'Armor Class', 'hp': 'Hit Points', 'speed': 'Speed', 'saves': 'Saving Throws', 'd_resistances': 'Damage Resistances?', 'd_vulnerabilities': 'Damage Vulnerabilities', 'd_immunities': 'Damage Immunities', 'c_immunities': 'Condition Immunities', 'senses': 'Senses', 'langs': 'Languages', 'skills': 'Skills'}
- desc = {}
+ desc = {'entry': 'creature'}
for name in names2names:
m = re.search('(\*\*{}\.?\*\*)(.*)'.format(names2names[name]), data)
if m:
@@ -28,7 +28,7 @@ def processMonster(data, weapons, armors, spells):
qualifiers.append('nonmagical')
if 'that aren\'t' in part:
qualifiers.append('non-' + re.search('(?<=that aren\'t ).*$', part).group(0))
- for typ in re.findall('([a-z]+(?=,)|^[a-z]+$|(?<=, )[a-z]+$|(?<=and )[a-z]+(?= from))', part):
+ for typ in re.findall('([a-z]+(?=,)|^[a-z]+$|(?<=, )[a-z]+$|(?<=and )[a-z]+(?= from)|(?<=and )[a-z]+(?= \(from))', part):
desc[name].append({'type': typ, 'qualifiers': qualifiers})
# Calc things about hp
hitdieMatch = re.search('(\d+)d(\d+)', desc['hp'])
@@ -40,7 +40,7 @@ def processMonster(data, weapons, armors, spells):
desc['cr'] = float(re.search('(?<=cr: ).*', data).group(0).strip())
description = re.search('(?<=_).*(?=_)', data).group(0).strip()
desc['size'] = description.split(' ')[0]
- desc['alignment'] = description.split(', ')[1]
+ desc['alignment'] = description.split(', ')[-1]
desc['stats'] = {ability: int(score.strip().split(' ')[0]) for ability, score in zip(['str', 'dex', 'con', 'int', 'wis', 'cha'], re.findall('(?<=\|) *\d.*?(?=\|)', data))}
def getBonus(ability):
return (desc['stats'][ability] - 10) // 2
@@ -73,7 +73,7 @@ def processMonster(data, weapons, armors, spells):
if armorDict['name'] == a:
found = True
bonus = armorDict['ac']
- typ = armorDict['type']
+ typ = armorDict['armor_type']
#desc['inventory'].append(armorDict)
desc['inventory'].append({'name': a, 'type': 'armor', 'text': '{} armor'.format(a)})
break
@@ -99,10 +99,10 @@ def processMonster(data, weapons, armors, spells):
del desc['ac']
# Search for a description section
- desc['description'] = ''
+ desc['text'] = ''
description = re.search('(?s)(?<={}).*?(?=###|$)'.format('### Description'), data)
if description:
- desc['description'] = description.group(0).strip()
+ desc['text'] = description.group(0).strip()
# Next do sections
names2sectHeads = {'feature': '\*\*Challenge\*\*', 'action': '### Actions', 'legendary_action': '### Legendary Actions', 'reaction': '### Reactions'}
@@ -116,7 +116,7 @@ def processMonster(data, weapons, armors, spells):
#if text and re.search('\w', text.group(1)):
# desc[name]['_text'] = text.group(1).strip()
for m in re.findall('(?s)\n\*\*(.*?)\.?\*\*(.*?)(?=\n\*\*|$)', section.group(0)):
- desc['features'].append({'name': m[0].lower(), 'text': m[1].strip(), 'type': name})
+ desc['features'].append({'entry': 'feature', 'name': m[0].lower(), 'text': m[1].strip(), 'type': name})
# Next, simplify and codify a few things
# Guess the proficiency bonus
desc['prof'] = int(max(0, (desc['cr']-1) // 4) + 2)
@@ -196,12 +196,12 @@ def processMonster(data, weapons, armors, spells):
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():
action['attack'][name] = value
- if action['attack']['type'] != 'unknown':
+ if action['attack']['weapon_type'] != 'unknown':
#desc['inventory'].append(action['attack'])
desc['inventory'].append({'name': action['attack']['name'], 'type': 'weapon', 'text': action['text']})
elif 'spellcasting' in action['name']:
action['type'] = 'spellcasting'
- print('{} has spellcasting!'.format(desc['name']))
+ #print('{} has spellcasting!'.format(desc['name']))
abilities = ['Intelligence', 'Wisdom', 'Charisma']
for ability in abilities:
if ability in action['text']:
@@ -258,7 +258,7 @@ def processMonster(data, weapons, armors, spells):
action['name'] = 'spellcasting'
# Remove weapon actions from features (they were just added to inventory)
- desc['features'] = [a for a in desc['features'] if 'attack' not in a or a['attack']['type'] == 'unknown']
+ desc['features'] = [a for a in desc['features'] if 'attack' not in a or a['attack']['weapon_type'] == 'unknown']
# Get rid of precalculated passive perception
# It's always the last item in senses
passivePercep = int(desc['senses'].split(' ')[-1])
@@ -281,14 +281,14 @@ def dumpStuff(stuff, destDir):
with open(destDir + '/' + thing['name'].replace(' ', '_').replace('/', '') + '.json', 'w') as f:
json.dump(thing, f, indent=2)
-dumpStuff(weapons, 'items/weapons/')
-dumpStuff(armors, 'items/armor/')
-dumpStuff(spells, 'spells/')
+dumpStuff(weapons, 'parsed/items/weapons/')
+dumpStuff(armors, 'parsed/items/armor/')
+dumpStuff(spells, 'parsed/spells/')
-for monster in Path('../../5thSRD/docs/gamemaster_rules/monsters/').glob('*.md'):
+for monster in Path(utils.docsLoc + '/gamemaster_rules/monsters/').glob('*.md'):
#print('Processing {}'.format(monster))
with monster.open() as f:
data = f.read()
- Path('monsters/').mkdir(exist_ok=True)
- with open('monsters/' + monster.stem + '.json', 'w') as f:
+ Path('parsed/monsters/').mkdir(exist_ok=True)
+ with open('parsed/monsters/' + monster.stem + '.json', 'w') as f:
json.dump(processMonster(data, weapons, armors, spells), f, indent=2)