Refactor html->plaintext conversion (for bulk email) into separate library

This commit is contained in:
Sarina Canelake
2013-08-22 11:18:59 -04:00
parent f98d6764b2
commit b3bc4023b0
8 changed files with 53 additions and 10 deletions

View File

@@ -0,0 +1,23 @@
"""Provides a function to convert html to plaintext."""
from subprocess import Popen, PIPE
def html_to_text(html_message):
"""
Converts an html message to plaintext.
Currently uses lynx in a subprocess; should be refactored to
use something more pythonic.
"""
process = Popen(
['lynx', '-stdin', '-display_charset=UTF-8', '-assume_charset=UTF-8', '-dump'],
stdin=PIPE,
stdout=PIPE
)
# use lynx to get plaintext
(plaintext, err_from_stderr) = process.communicate(
input=html_message.encode('utf-8')
)
if err_from_stderr:
log.info(err_from_stderr)
return plaintext