Skip to content

Commit 2fe7eab

Browse files
committed
Add daily digest email template with quote, weather forecast, and trivia
1 parent e0f8971 commit 2fe7eab

File tree

3 files changed

+256
-44
lines changed

3 files changed

+256
-44
lines changed

start_your_day/backend/email.html

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
2+
<!DOCTYPE html>
3+
<html lang="en">
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Daily Digest - 09 December 2024</title>
8+
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap" rel="stylesheet">
9+
<style>
10+
body {
11+
font-family: 'Roboto', Arial, sans-serif;
12+
max-width: 600px;
13+
margin: 0 auto;
14+
padding: 20px;
15+
line-height: 1.6;
16+
color: #333;
17+
background-color: #f4f4f4;
18+
}
19+
.container {
20+
background-color: white;
21+
border-radius: 10px;
22+
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
23+
padding: 30px;
24+
}
25+
h1 {
26+
color: #2c3e50;
27+
text-align: center;
28+
border-bottom: 2px solid #3498db;
29+
padding-bottom: 10px;
30+
}
31+
.section {
32+
margin-bottom: 20px;
33+
padding: 15px;
34+
border-radius: 5px;
35+
}
36+
.quote {
37+
background-color: #f9e79f;
38+
font-style: italic;
39+
}
40+
.weather {
41+
background-color: #e6f2ff;
42+
}
43+
.wikipedia {
44+
background-color: #e8f6f3;
45+
}
46+
.footer {
47+
text-align: center;
48+
color: #7f8c8d;
49+
margin-top: 20px;
50+
}
51+
</style>
52+
</head>
53+
<body>
54+
<div class="container">
55+
<h1>🌞 Daily Digest</h1>
56+
<p style="text-align: center; color: #7f8c8d;">
57+
09 December 2024
58+
</p>
59+
60+
61+
<div class="section quote">
62+
<h2>📜 Quote of the Day</h2>
63+
<blockquote>
64+
<i> There is no spoon.</i>
65+
<footer>— Keanu Reeves, The Matrix, </footer>
66+
</blockquote>
67+
</div>
68+
69+
70+
<div class="section weather">
71+
<h2>🌦️ Weather Forecast</h2>
72+
<p><strong>Location:</strong> Franconville, FR</p>
73+
<ul>
74+
<li>2024-12-09 07:00:00: Overcast Clouds, 5.74°C</li><li>2024-12-09 10:00:00: Overcast Clouds, 5.6°C</li><li>2024-12-09 13:00:00: Overcast Clouds, 5.78°C</li><li>2024-12-09 16:00:00: Light Rain, 5.91°C</li><li>2024-12-09 19:00:00: Light Rain, 4.53°C</li><li>2024-12-09 22:00:00: Light Rain, 4.74°C</li><li>2024-12-10 01:00:00: Light Rain, 5.08°C</li><li>2024-12-10 04:00:00: Overcast Clouds, 4.53°C</li><li>2024-12-10 07:00:00: Overcast Clouds, 4.63°C</li>
75+
</ul>
76+
</div>
77+
78+
79+
<div class="section wikipedia">
80+
<h2>🧠 Did You Know?</h2>
81+
<p>With Billie in Mind is a solo tribute album by pianist Teddy Wilson featuring tunes associated with Billie Holiday that were recorded in New York City in 1972 and released on the Chiaroscuro label. The album was reissued on CD in 1990 with six additional tracks.</p>
82+
<p><em>Source: <a href="https://en.wikipedia.org/wiki/With_Billie_in_Mind">https://en.wikipedia.org/wiki/With_Billie_in_Mind</a></em></p>
83+
</div>
84+
85+
<div class="footer">
86+
<p>✨ Have a Fantastic Day! ✨</p>
87+
</div>
88+
</div>
89+
</body>
90+
</html>
91+

start_your_day/backend/email.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
🌞 Daily Digest - 09 December 2024 🌞
2+
==================================================
3+
4+
📜 Quote of the Day 📜
5+
-------------------------
6+
❝ There is no spoon.❞
7+
- Keanu Reeves, The Matrix,
8+
9+
🌦️ Weather Forecast: Franconville, FR 🌦️
10+
--------------------------------------------------
11+
• 2024-12-09 07:00:00: Overcast Clouds | 5.74°C
12+
• 2024-12-09 10:00:00: Overcast Clouds | 5.6°C
13+
• 2024-12-09 13:00:00: Overcast Clouds | 5.78°C
14+
• 2024-12-09 16:00:00: Light Rain | 5.91°C
15+
• 2024-12-09 19:00:00: Light Rain | 4.53°C
16+
• 2024-12-09 22:00:00: Light Rain | 4.74°C
17+
• 2024-12-10 01:00:00: Light Rain | 5.08°C
18+
• 2024-12-10 04:00:00: Overcast Clouds | 4.53°C
19+
• 2024-12-10 07:00:00: Overcast Clouds | 4.63°C
20+
21+
🧠 Did You Know? 🧠
22+
-------------------------
23+
With Billie in Mind is a solo tribute album by pianist Teddy Wilson featuring tunes associated with Billie Holiday that were recorded in New York City in 1972 and released on the Chiaroscuro label. The album was reissued on CD in 1990 with six additional tracks.
24+
(Source: https://en.wikipedia.org/wiki/With_Billie_in_Mind)
25+
26+
✨ Have a Fantastic Day! ✨

start_your_day/backend/emails.py

Lines changed: 139 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,184 @@
11
import content
22
import datetime
3+
import smtplib
4+
from email.message import EmailMessage
5+
from dotenv import load_dotenv # Import the load_dotenv function from the python-dotenv module
6+
import os
7+
8+
9+
load_dotenv() # Load environment variables from the .env file
10+
311

412
class DailyEmail:
5-
# Define the structure of the daily email content
613
def __init__(self):
714
self.content = {
815
"quote": {"include": True, "content": content.get_random_quote()},
916
"weather": {"include": True, "content": content.get_weather_forecast()},
1017
"wikipedia": {"include": True, "content": content.get_wikipedia_article()}
1118
}
19+
20+
self.recipient_list = {
21+
"email": os.getenv('RECIPIENT_EMAIL') # Get the recipient email address from environment variables
22+
}
23+
24+
self.sender_credentials = {
25+
"email": os.getenv('SENDER_EMAIL'), # Get the sender email address from environment variables
26+
"password": os.getenv('SENDER_PASSWORD') # Get the sender email password from environment variables
27+
}
28+
29+
30+
"""
31+
Generate email message body as plain text and HTML content.
32+
"""
1233

13-
# Format the general message of the email
1434
def format_email(self):
15-
# Define the plain text email message structure
16-
message = f"Good morning!\n\nHere's your daily email for {datetime.datetime.now().strftime('%d-%m-%Y')}:\n\n"
35+
# Enhanced text formatting with more visual separation and emphasis
36+
message = f"🌞 Daily Digest - {datetime.datetime.now().strftime('%d %B %Y')} 🌞\n"
37+
message += "=" * 50 + "\n\n"
1738

18-
# Add the quote to the message
39+
# Quote section with decorative borders
1940
if self.content['quote']['include']:
2041
quote = self.content['quote']['content']
21-
message += f"Quote of the day: '{quote['quote']}' - {quote['author']}\n\n"
42+
message += "📜 Quote of the Day 📜\n"
43+
message += "-" * 25 + "\n"
44+
message += f"❝{quote['quote']}\n"
45+
message += f" - {quote['author']}\n\n"
2246

23-
# Add the weather forecast to the message
47+
# Weather section with emoji and detailed formatting
2448
if self.content['weather']['include']:
2549
weather = self.content['weather']['content']
26-
message += f"Today's weather forecast for {weather['city']}, {weather['country']}:\n"
50+
message += f"🌦️ Weather Forecast: {weather['city']}, {weather['country']} 🌦️\n"
51+
message += "-" * 50 + "\n"
2752
for period in weather['forecast']:
28-
message += f" - {period['timestamp']}: {period['description']}, {period['temperature']}°C\n"
53+
message += f"{period['timestamp']}: {period['description']} | {period['temperature']}°C\n"
2954
message += "\n"
3055

31-
# Add the Wikipedia article to the message
56+
# Wikipedia section with engaging header
3257
if self.content['wikipedia']['include']:
3358
article = self.content['wikipedia']['content']
34-
message += f"Did you know? {article['extract']} (source: {article['url']})\n\n"
59+
message += "🧠 Did You Know? 🧠\n"
60+
message += "-" * 25 + "\n"
61+
message += f"{article['extract']}\n"
62+
message += f"(Source: {article['url']})\n\n"
3563

36-
# Add a closing message
37-
message += "Have a great day!"
64+
message += "✨ Have a Fantastic Day! ✨"
3865

39-
# Generate HTML content for the email
66+
# Enhanced HTML with more sophisticated styling and responsive design
4067
html = f"""
41-
<html>
68+
<!DOCTYPE html>
69+
<html lang="en">
4270
<head>
71+
<meta charset="UTF-8">
72+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
73+
<title>Daily Digest - {datetime.datetime.now().strftime('%d %B %Y')}</title>
74+
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap" rel="stylesheet">
4375
<style>
4476
body {{
45-
font-family: Arial, sans-serif;
77+
font-family: 'Roboto', Arial, sans-serif;
78+
max-width: 600px;
79+
margin: 0 auto;
80+
padding: 20px;
4681
line-height: 1.6;
4782
color: #333;
83+
background-color: #f4f4f4;
84+
}}
85+
.container {{
86+
background-color: white;
87+
border-radius: 10px;
88+
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
89+
padding: 30px;
4890
}}
4991
h1 {{
5092
color: #2c3e50;
93+
text-align: center;
94+
border-bottom: 2px solid #3498db;
95+
padding-bottom: 10px;
5196
}}
52-
p {{
53-
margin: 10px 0;
97+
.section {{
98+
margin-bottom: 20px;
99+
padding: 15px;
100+
border-radius: 5px;
54101
}}
55102
.quote {{
103+
background-color: #f9e79f;
56104
font-style: italic;
57-
color: #e74c3c;
58105
}}
59106
.weather {{
60-
background-color: #ecf0f1;
61-
padding: 10px;
62-
border-radius: 5px;
107+
background-color: #e6f2ff;
63108
}}
64109
.wikipedia {{
65-
background-color: #f9e79f;
66-
padding: 10px;
67-
border-radius: 5px;
110+
background-color: #e8f6f3;
111+
}}
112+
.footer {{
113+
text-align: center;
114+
color: #7f8c8d;
115+
margin-top: 20px;
68116
}}
69117
</style>
70118
</head>
71119
<body>
72-
<h1>Good Morning!</h1>
73-
<p>Here's your daily email for {datetime.datetime.now().strftime('%d-%m-%Y')}:</p>
74-
75-
{f"<p class='quote'><b>Quote of the day:</b> '{quote['quote']}' - {quote['author']}</p>" if self.content['quote']['include'] else ""}
76-
77-
{f"<div class='weather'><b>Today's weather forecast for {weather['city']}, {weather['country']}:</b><ul>" +
78-
"".join([f"<li>{period['timestamp']}: {period['description']}, {period['temperature']}°C</li>" for period in weather['forecast']]) +
79-
"</ul></div>" if self.content['weather']['include'] else ""}
80-
81-
{f"<div class='wikipedia'><b>Did you know?</b> {article['extract']}<br>Source: <a href='{article['url']}'>{article['url']}</a></div>" if self.content['wikipedia']['include'] else ""}
82-
83-
<p>Have a great day!</p>
120+
<div class="container">
121+
<h1>🌞 Daily Digest</h1>
122+
<p style="text-align: center; color: #7f8c8d;">
123+
{datetime.datetime.now().strftime('%d %B %Y')}
124+
</p>
125+
126+
{f'''
127+
<div class="section quote">
128+
<h2>📜 Quote of the Day</h2>
129+
<blockquote>
130+
<i>{quote['quote']}</i>
131+
<footer>— {quote['author']}</footer>
132+
</blockquote>
133+
</div>''' if self.content['quote']['include'] else ''}
134+
135+
{f'''
136+
<div class="section weather">
137+
<h2>🌦️ Weather Forecast</h2>
138+
<p><strong>Location:</strong> {weather['city']}, {weather['country']}</p>
139+
<ul>
140+
{''.join([f"<li>{period['timestamp']}: {period['description']}, {period['temperature']}°C</li>" for period in weather['forecast']])}
141+
</ul>
142+
</div>''' if self.content['weather']['include'] else ''}
143+
144+
{f'''
145+
<div class="section wikipedia">
146+
<h2>🧠 Did You Know?</h2>
147+
<p>{article['extract']}</p>
148+
<p><em>Source: <a href="{article['url']}">{article['url']}</a></em></p>
149+
</div>''' if self.content['wikipedia']['include'] else ''}
150+
151+
<div class="footer">
152+
<p>✨ Have a Fantastic Day! ✨</p>
153+
</div>
154+
</div>
84155
</body>
85156
</html>
86157
"""
87158

88159
return message, html
89160

161+
"""
162+
Send the formatted email to the recipient.
163+
"""
90164
def send_email(self):
91-
pass
92-
93-
94-
95-
96-
165+
# Build the email message
166+
message = EmailMessage()
167+
message['Subject'] = f"🌞 Daily Digest - {datetime.datetime.now().strftime('%d %B %Y')} 🌞"
168+
message['From'] = self.sender_credentials['email']
169+
message['To'] = self.recipient_list['email']
170+
171+
# Add plain text and HTML content
172+
message_body_text, message_body_html = self.format_email()
173+
message.set_content(message_body_text)
174+
message.add_alternative(message_body_html, subtype='html')
175+
176+
# Send the email with the SMTP server
177+
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as server:
178+
server.login(self.sender_credentials['email'], self.sender_credentials['password'])
179+
server.send_message(message)
180+
server.quit()
181+
print("Email sent successfully!")
97182

98183
if __name__ == '__main__':
99184
# Create a DailyEmail instance
@@ -104,4 +189,14 @@ def send_email(self):
104189

105190
# Print the email content
106191
print(message)
107-
print(html)
192+
print("\n--- HTML Content ---")
193+
print(html)
194+
195+
# Save the email content to files
196+
with open('email.html', 'w', encoding='utf-8') as file:
197+
file.write(html)
198+
with open('email.txt', 'w', encoding='utf-8') as file:
199+
file.write(message)
200+
201+
# Send the email
202+
email.send_email()

0 commit comments

Comments
 (0)