diff options
author | Your Name <you@example.com> | 2021-04-13 16:16:27 -0400 |
---|---|---|
committer | Your Name <you@example.com> | 2021-04-13 16:16:27 -0400 |
commit | 9034c3d2533177f7cb7a7ce939ec53f7fa63f60e (patch) | |
tree | 49bf01a4682c251cb3778f563afeb7e1ec8d41c7 /parser/utils.py | |
parent | 2ab51e507d620c4479e07ca0ec47d22c8c66bc90 (diff) | |
download | dmtool-9034c3d2533177f7cb7a7ce939ec53f7fa63f60e.tar.gz dmtool-9034c3d2533177f7cb7a7ce939ec53f7fa63f60e.tar.bz2 dmtool-9034c3d2533177f7cb7a7ce939ec53f7fa63f60e.zip |
Added spells
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 |