diff options
Diffstat (limited to 'parser/utils.py')
-rwxr-xr-x | parser/utils.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/parser/utils.py b/parser/utils.py index 1798621..4b7b3f7 100755 --- a/parser/utils.py +++ b/parser/utils.py @@ -150,3 +150,22 @@ def formatWeapon(name, rangeShort, rangeLong, reach, dmgType, dmgCount, dmgSides if weapon['name'] == name: baseWeapon = weapon return {'name': name, 'cost': baseWeapon['cost'], 'damage': {'dmg_type': dmgType, 'dmg_die_count': dmgCount, 'dmg_die_sides': dmgSides}, 'weight': baseWeapon['weight'], 'range': [rangeShort, rangeLong], 'reach': reach, 'properties': baseWeapon['properties'], 'type': baseWeapon['type'], 'text': text} + +spells = [] +def getSpells(): + global spells + if spells: + return spells + names2names = {'name': 'name', 'level': 'level', 'school': 'school', 'classes': 'classes', 'casting_time': 'Casting Time', 'range': 'Range', 'components': 'Components', 'duration': 'Duration'} + from pathlib import Path + for s in Path('../../5thSRD/docs/spellcasting/spells/').iterdir(): + with s.open() as f: + data = f.read() + spell = {} + for name in names2names: + spell[name] = re.search('(?sm)[\*]*{}[\*:]* (.*?)^[a-zA-Z#\*]'.format(names2names[name]), data).group(1).strip() + spell['level'] = int(spell['level']) + spell['text'] = re.search('(?sm)\*\*Duration:?\*\*:? .*?$(.*)', data).group(1).strip() + spell['classes'] = spell['classes'].split() + spells.append(spell) + return spells |