Contact me to be added to this repository. Push the creations you make for D&D, and they will be displayed in a nice website. See the website for how to contribute.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

37 lines
1.1 KiB

import glob
def parse_headers(spell_text):
"""Takes in the 'tail' part of a spell file"""
lines = spell_text.split("\n")
while len(lines[0].strip()) == 0:
lines = lines[1:]
heads = []
while lines:
hd, col, val = lines[0].partition(':')
if not col:
return heads,'\n'.join(lines)
heads.append((hd.strip(), val.strip()))
lines = lines[1:]
return heads, '\n'.join(lines) # Should be empty, but :shrug:
def test_spell_parse():
f = open("../Spells/deceptive_sending.txt",'r')
text = '\n'.join(f.read().split("\n")[2:])
print(parse_headers(text))
def get_items(items_dir):
items_list = []
for fname in glob.glob(items_dir):
f = open(fname,'r')
lines = f.read().split('\n')
title = lines[0]
lines = lines[1:]
while not (set(lines[0]) - set('-')):
lines = lines[1:]
heads, body= parse_headers('\n'.join(lines))
items_list.append((title,heads,body))
items_list.sort(key = lambda data: data[0])
return items_list