1
0

Send email notifications.

This commit is contained in:
2019-02-25 17:11:59 +01:00
parent 3f69e02019
commit c0fab2a4f8

View File

@@ -7,11 +7,17 @@ import datetime
import json
import os
import textwrap
import smtplib
import sys
from collections import defaultdict
from email.message import EmailMessage
from urllib.request import urlopen
EMAIL_SENDER = 'Witbierbot <witbier@example.org>'
EMAIL_RECIPIENT = 'RECIPIENT'
def load_weather():
url = 'https://api.openweathermap.org/data/2.5/forecast?q=Leiden' \
+ '&units=metric' \
@@ -51,7 +57,17 @@ def notify(best_day, best_temp):
'''
message = textwrap.dedent(message)
print(message)
report_date = datetime.datetime.now().strftime('%d/%m/%y')
mail = EmailMessage()
mail.set_content(message)
mail['Subject'] = 'Witbier alert voor ' + report_date
mail['To'] = EMAIL_RECIPIENT
mail['From'] = EMAIL_SENDER
with smtplib.SMTP('localhost') as smtp:
smtp.send_message(mail)
def main():