diff --git a/scripts/lessonEmail.py b/scripts/lessonEmail.py new file mode 100644 index 000000000..35d4b857d --- /dev/null +++ b/scripts/lessonEmail.py @@ -0,0 +1,161 @@ +import datetime +import yaml +import smtplib +import argparse +from email.mime.multipart import MIMEMultipart +from email.mime.text import MIMEText + + +def get_event(): + """Retrieve event matching the current date + + Args: + None + + Returns: + event (:obj:'dict'): Dictionary storing information on current day's event + """ + + today = datetime.date.today() + + # YY/mm/dd + current_date = today.strftime("%Y-%m-%d") # E.g. 2019-04-18 + + with open('../_data/events.yml', 'r') as stream: + + # Load all events with as separate list elements + all_events = yaml.safe_load(stream) + + # Loop through list and parse event dictionary + for event in all_events: + + # Get only event matching current date + # if event['date'] == current_date: + if event['key'] == 'project-management': # Uncomment for testing only. + return event + + +def create_message(sender, receivers, event): + """Parses today's event dictionary and composes HTML message with details + + Args: + sender ('str'): Sender Email. Provided as command-line. Must be UToronto Email + receivers (:obj:'list' of :obj:'str'): List with receiving Emails as string elements. Email sent to all Emails in list. + event (:obj:'dict'): Dictionary storing information on current day's event + + Returns: + msg (:obj:'MIMEMultipart'): Email in HTML format. See email.mime.multipart.MIMEMultipart(). + """ + + # If event not empty, retrieve details and compose message. + if event: + + path_to_script = 'https://github.com/utm-coders/studyGroup/blob/gh-pages/scripts/lessonEmail.py' + + date = event['date'] + key = event['key'] + description = event['description'] + subject = '{0} Programming workshop: {1}'.format(date, key) + youtube_link = event['youtube_link'] + # print(youtube_link) + + # Create email MIMEMultipart object + msg = MIMEMultipart() + msg['From'] = sender + msg['To'] = ', '.join(receivers) + msg['Subject'] = subject + + body = """\ + +
+ + Hey all, ++ Here is the link to today's programming workshop: +
+ +
+ Lesson name: {0}
+ Lesson description: {1}
+ Link to lesson: {2}
+
+ This Email was sent automatically using + this script +
+