3

I'm looking for a python solution to create a static .html that can be sent out via email, either attached or embedded in the email (ignore this latter option if it requires a lot more work). I do not have requirements for what regards the layout of the .html. The focus here is in identifying the less painful solution for to generate an offline .html.

A potential solution could be along the lines of the following pseudo-code.

from some_unknown_pkg import StaticHTML

# Initialise instance
newsletter = StaticHTML()

# Append charts, tables and text to blank newsletter.
newsletter.append(text_here)
newsletter.append(interactive_chart_generated_with_plotly)
newsletter.append(more_text_here)
newsletter.append(a_png_file_loaded_from_local_pc)



# Save newsletter to .html, ready to be sent out.
newsletter.save_to_html('newsletter.html')

Where 'newsletter.html' can be opened in a whatever browser. Just to provide a bit more context, this .html is supposed to be sent out to a few selected people inside my company and contains sensible data. I'm using plotly to generate interactive charts to be inserted in the .html.

3 Answers 3

3

Start your python module with by importing sys module and redirect stdout to newsletter.html

import sys
sys.stdout = open('newsletter.html','w')

This will redirect any output generated to the html file. Now, just use the print command in python to transmit html tags to the file. For eg try:

print "<html>"
print "<p> This is my NewsLetter </p>"
print "</html>"`

This code snippet will create a basic HTML file. Now, you can open this file in any browser. For sending email you can use email and smtplib modules of python.

Sign up to request clarification or add additional context in comments.

Comments

2

Possible solution here

Seems package in that answer is exactly you want. Docs: http://www.yattag.org/

Another pretty nice package here.

Comments

1

The Dominate package looks like it provides a simple and intuitive way to create HTML pages. https://www.yattag.org/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.