newsletter2.0 / newsletter_generator.py
claytonsamples's picture
Create newsletter_generator.py
ed86cf5
raw
history blame contribute delete
728 Bytes
# Import necessary libraries
from jinja2 import Environment, FileSystemLoader
class NewsletterGenerator:
def __init__(self, summaries, template='templates/newsletter.html'):
self.summaries = summaries
self.template = template
def generate_newsletter(self):
# Load the Jinja2 environment
env = Environment(loader=FileSystemLoader('.'))
template = env.get_template(self.template)
# Render the template with the summaries
newsletter = template.render(summaries=self.summaries)
# Save the newsletter to a HTML file
with open('newsletter.html', 'w') as f:
f.write(newsletter)
print("Newsletter has been generated successfully!")