def save_to_file(filename, text):
clean_filename = filename.replace('/', '-').strip('"')
with open(clean_filename, 'w+') as f:
f.write(text.encode('utf-8'))
def html_to_poetry(p):
return str(p)[4:][:-4].replace('
', '')
def to_poems(ps):
is_title = lambda p: p.findAll('h4')
text = ''
for p in ps:
if is_title(p):
title = p.findAll('h4')[0].text
text += '\n\n'.join(['', title.capitalize(), ''])
else:
text += '\n'.join(['', html_to_poetry(p).decode('utf-8')])
return text[2:]