From d70629daf0de6cc42f8c8f39b590ed87c9b3e23e Mon Sep 17 00:00:00 2001 From: Christian Cleberg Date: Mon, 22 May 2023 15:18:04 -0500 Subject: initial commit --- main.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 main.py (limited to 'main.py') diff --git a/main.py b/main.py new file mode 100644 index 0000000..bf3d530 --- /dev/null +++ b/main.py @@ -0,0 +1,39 @@ +# Import Python packages +from email.mime.text import MIMEText +import smtplib +import json +import requests + +# Send API request for a random poem +json_data = requests.get('https://poetrydb.org/random').json() + +# Extract the poem details from the JSON response +title = json_data[0]['title'] +author = json_data[0]['author'] +line_count = json_data[0]['linecount'] +lines = '' +for line in json_data[0]['lines']: + lines = lines + line + "\n" + +# A test print() statement to ensure the request and parsing processed the data +# correctly +# print(title, "\n", author, "\n\n", lines) + +msg_body = title + "\n" + author + "\n\n" + lines + +# Create plaintext message container +msg = MIMEText(msg_body) + +# Prepare the metadata of the message +sender_email = '' +recipient_emails = '' +msg['Subject'] = 'Your Daily Poem (' + line_count + ' lines)' +msg['From'] = sender_email +msg['To'] = recipient_email + +# Send the message via our own SMTP server, but don't include the +# envelope header. +smtp_server = 'localhost' +s = smtplib.SMTP(smtp_server) +s.sendmail(sender_email, [recipient_emails], msg.as_string()) +s.quit() -- cgit v1.2.3-70-g09d2