aboutsummaryrefslogtreecommitdiff
path: root/parser/scrapeToJson.py
diff options
context:
space:
mode:
Diffstat (limited to 'parser/scrapeToJson.py')
-rwxr-xr-xparser/scrapeToJson.py34
1 files changed, 17 insertions, 17 deletions
diff --git a/parser/scrapeToJson.py b/parser/scrapeToJson.py
index 5eacb5a..cbe9999 100755
--- a/parser/scrapeToJson.py
+++ b/parser/scrapeToJson.py
@@ -13,7 +13,7 @@ def processMonster(data, weapons, armors, spells):
desc = Creature()
desc['entry'] = 'creatures'
for name in names2names:
- m = re.search('(\*\*{}\.?\*\*)(.*)'.format(names2names[name]), data)
+ m = re.search(r'(\*\*{}\.?\*\*)(.*)'.format(names2names[name]), data)
if m:
desc[name] = m.group(2).strip()
else:
@@ -33,23 +33,23 @@ def processMonster(data, weapons, armors, spells):
if 'nonmagical' in part:
qualifiers.append('nonmagical')
if 'that aren\'t' in part:
- qualifiers.append('non-' + re.search('(?<=that aren\'t ).*$', part).group(0))
+ qualifiers.append('non-' + re.search(r"(?<=that aren't ).*$", part).group(0))
if 'not made with ' in part:
- qualifiers.append('non-' + re.search('(?<=not made with )\w*', part).group(0))
- for typ in re.findall('([a-z]+(?=,)|^[a-z]+$|(?<=, )[a-z]+$|(?<=and )[a-z]+(?= from)|(?<=and )[a-z]+(?= \(from))', part):
+ qualifiers.append('non-' + re.search(r'(?<=not made with )\w*', part).group(0))
+ for typ in re.findall(r'([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'])
+ hitdieMatch = re.search(r'(\d+)d(\d+)', desc['hp'])
desc['hit_die_count'] = int(hitdieMatch.group(1))
desc['hit_die_sides'] = int(hitdieMatch.group(2))
del desc['hp']
- desc['name'] = re.search('(?<=name: ).*', data).group(0).strip()
- desc['type'] = re.search('(?<=type: ).*', data).group(0).strip()
+ desc['name'] = re.search(r'(?<=name: ).*', data).group(0).strip()
+ desc['type'] = re.search(r'(?<=type: ).*', data).group(0).strip()
desc['cr'] = float(re.search('(?<=cr: ).*', data).group(0).strip())
- description = re.search('(?<=_).*(?=_)', data).group(0).strip()
+ description = re.search(r'(?<=_).*(?=_)', data).group(0).strip()
desc['size'] = description.split(' ')[0]
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))}
+ desc['stats'] = {ability: int(score.strip().split(' ')[0]) for ability, score in zip(['str', 'dex', 'con', 'int', 'wis', 'cha'], re.findall(r'(?<=\|) *\d.*?(?=\|)', data))}
desc['inventory'] = [] # Fill with weapons and armor
desc['observant'] = False # maybe set to true later
# Add a few null-valued items that will be set when the creature is first generated
@@ -61,7 +61,7 @@ def processMonster(data, weapons, armors, spells):
correctAC = int(desc['ac'].split(' ')[0] if ' ' in desc['ac'] else desc['ac'])
natural = ''
armorBonus = 0
- armor = re.search('(?<=\().*(?=\))', desc['ac'])
+ armor = re.search(r'(?<=\().*(?=\))', desc['ac'])
if armor:
armor = armor.group(0).lower()
if ',' in armor:
@@ -71,7 +71,7 @@ def processMonster(data, weapons, armors, spells):
for a in armor:
a = a.strip()
# If it has "armor" in it, remove that
- a = re.search('^(.*?)(?: armor)?$', a).group(1)
+ a = re.search(r'^(.*?)(?: armor)?$', a).group(1)
#print('Working with {}'.format(a))
if a == 'natural' or a == 'patchwork' or 'scraps' in a:
natural = a
@@ -111,28 +111,28 @@ def processMonster(data, weapons, armors, spells):
# Search for a description section
desc['text'] = ''
- description = re.search('(?s)(?<={}).*?(?=###|$)'.format('### Description'), data)
+ description = re.search(r'(?s)(?<={}).*?(?=###|$)'.format('### Description'), data)
if description:
desc['text'] = description.group(0).strip()
else:
# Try looking for the last entry (**something**) with an empty line and then one or more paragraphs before end of file
- description = re.search('(?s)(?<=\*\*).*\n\n(.*?)(?=###|$)', data)
+ description = re.search(r'(?s)(?<=\*\*).*\n\n(.*?)(?=###|$)', data)
if description:
#print(f'Found description without a header for {desc["name"]}')
desc['text'] = description.group(1).strip()
# Next do sections
- names2sectHeads = {'feature': '\*\*Challenge\*\*', 'action': '### Actions', 'legendary_action': '### Legendary Actions', 'reaction': '### Reactions'}
+ names2sectHeads = {'feature': r'\*\*Challenge\*\*', 'action': '### Actions', 'legendary_action': '### Legendary Actions', 'reaction': '### Reactions'}
# We put them all in "features" list
desc['features'] = []
for name in names2sectHeads:
- section = re.search('(?s)(?<={}).*?(?=###|$)'.format(names2sectHeads[name]), data)
+ section = re.search(r'(?s)(?<={}).*?(?=###|$)'.format(names2sectHeads[name]), data)
if section:
# There might be a special section text as the first new line after the header
#text = re.match('(?s)(\s*\w[^\*].*?)([\r\n]+[\*#]|$)', '\n'.join(section.group(0).split('\n')[1:]))
#if text and re.search('\w', text.group(1)):
# desc[name]['_text'] = text.group(1).strip()
- for m in re.findall('(?s)\n\*\*(.*?)\.?\*\*(.*?)(?=\n\*\*|\n\n|$)', section.group(0)):
+ for m in re.findall(r'(?s)\n\*\*(.*?)\.?\*\*(.*?)(?=\n\*\*|\n\n|$)', section.group(0)):
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
@@ -157,7 +157,7 @@ def processMonster(data, weapons, armors, spells):
print('Things came out funny for {}; {} save has bonus {}, but proficiency is {} and the relevant ability ({}) gets {}'.format(desc['name'], ability, int(save.split('+')[1]), desc['prof'], ability, desc.getBonus(ability)))
desc['saves'].append(ability)
for action in desc['features']:
- if re.match('.*Attack:', action['text']):
+ if re.match(r'.*Attack:', action['text']):
attacks.procAttackAction(desc, action, weapons)
elif 'spellcasting' in action['name']:
attacks.procSpellAction(desc, action, spells)