claytonsamples commited on
Commit
ed86cf5
1 Parent(s): 2db5eff

Create newsletter_generator.py

Browse files
Files changed (1) hide show
  1. newsletter_generator.py +21 -0
newsletter_generator.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Import necessary libraries
2
+ from jinja2 import Environment, FileSystemLoader
3
+
4
+ class NewsletterGenerator:
5
+ def __init__(self, summaries, template='templates/newsletter.html'):
6
+ self.summaries = summaries
7
+ self.template = template
8
+
9
+ def generate_newsletter(self):
10
+ # Load the Jinja2 environment
11
+ env = Environment(loader=FileSystemLoader('.'))
12
+ template = env.get_template(self.template)
13
+
14
+ # Render the template with the summaries
15
+ newsletter = template.render(summaries=self.summaries)
16
+
17
+ # Save the newsletter to a HTML file
18
+ with open('newsletter.html', 'w') as f:
19
+ f.write(newsletter)
20
+
21
+ print("Newsletter has been generated successfully!")