From 9034c3d2533177f7cb7a7ce939ec53f7fa63f60e Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 13 Apr 2021 16:16:27 -0400 Subject: Added spells --- parser/utils.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'parser/utils.py') 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 -- cgit v1.2.3