aboutsummaryrefslogtreecommitdiff
path: root/content/blog/2022-06-22-daily-poetry.org
diff options
context:
space:
mode:
authorChristian Cleberg <[email protected]>2025-11-11 22:49:13 -0600
committerChristian Cleberg <[email protected]>2025-11-11 22:49:13 -0600
commit51a7a02f0c96d49b68fbcc155414c218207fa270 (patch)
tree845af8aad0e8769352efc02fcd1044eed9cc1ec1 /content/blog/2022-06-22-daily-poetry.org
parent7d3e80ebf1dc770eac0e21890b74f18ba2d15a6b (diff)
downloadcleberg.net-51a7a02f0c96d49b68fbcc155414c218207fa270.tar.gz
cleberg.net-51a7a02f0c96d49b68fbcc155414c218207fa270.tar.bz2
cleberg.net-51a7a02f0c96d49b68fbcc155414c218207fa270.zip
fix grammar in 2022 posts
Diffstat (limited to 'content/blog/2022-06-22-daily-poetry.org')
-rw-r--r--content/blog/2022-06-22-daily-poetry.org74
1 files changed, 35 insertions, 39 deletions
diff --git a/content/blog/2022-06-22-daily-poetry.org b/content/blog/2022-06-22-daily-poetry.org
index cb0a73f..a51db06 100644
--- a/content/blog/2022-06-22-daily-poetry.org
+++ b/content/blog/2022-06-22-daily-poetry.org
@@ -14,8 +14,8 @@ I use to email myself plaintext poems daily, visit the repository:
Most of my programming projects are small, random projects that are made
strictly to fix some small problem I have or enhance my quality of life.
-In this case, I was looking for a simply and easy way to get a daily
-dose of literature or poetry to read in the mornings.
+In this case, I was looking for a simply and easy way to get a daily dose of
+literature or poetry to read in the mornings.
However, I don't want to sign up for a random mailing list on just any
website. I also don't want to have to work to find the reading content
@@ -29,21 +29,20 @@ a daily basis, and scheduled to deliver automatically.
This solution uses Python and email, so the following process requires
the following to be installed:
-1. An SMTP server, which can be as easy as installing =mailutils= if
- you're on a Debian-based distro.
+1. A Simple Mail Transfer Protocol (SMTP) server, which can be as easy as
+ installing =mailutils= if you're on a Debian-based distribution.
2. Python (& pip!)
-3. The following Python packages: =email=, =smtplib=, =json=, and
- =requests=
+3. The following Python packages: =email=, =smtplib=, =json=, and =requests=
* Breaking Down the Logic
-I want to break down the logic for this program, as it's quite simple
-and informational.
+I want to break down the logic for this program, as it's quite simple and
+informational.
** Required Packages
-This program starts with a simple import of the required packages, so I
-wanted to explain why each package is used:
+This program starts with a simple import of the required packages, so I wanted
+to explain why each package is used:
#+begin_src python
from email.mime.text import MIMEText # Required for translating MIMEText
@@ -54,15 +53,15 @@ import requests # Required to send out a request to the API
** Sending the API Request
-Next, we need to actually send the API request. In my case, I'm calling
-a random poem from the entire API. If you want, you can call specific
-poems or authors from this API.
+Next, we need to actually send the application programming interface (API)
+request. In my case, I'm calling a random poem from the entire API. If you want,
+you can call specific poems or authors from this API.
#+begin_src python
json_data = requests.get('https://poetrydb.org/random').json()
#+end_src
-This gives us the following result in JSON:
+This gives us the following result in JSON (JavaScript Object Notation):
#+begin_src json
[
@@ -94,12 +93,12 @@ This gives us the following result in JSON:
** Parsing the API Results
-In order to parse this into a readable format, we need to use the =json=
-package and extract the fields we want. In the example below, I am
-grabbing every field presented by the API.
+In order to parse this into a readable format, we need to use the =json= package
+and extract the fields we want. In the example below, I am grabbing every field
+presented by the API.
-For the actual poem content, we need to loop over each line in the
-=lines= variable since each line is a separate string by default.
+For the actual poem content, we need to loop over each line in the =lines=
+variable since each line is a separate string by default.
#+begin_quote
You /could/ also extract the title or author and make another call out
@@ -125,21 +124,20 @@ for line in json_data[0]['lines']:
** Composing the Email
-Now that I have all the data I need, I just need to compose it into a
-message and prepare the message metadata.
+Now that I have all the data I need, I just need to compose it into a message
+and prepare the message metadata.
-For my daily email, I want to see the title of the poem first, followed
-by the author, then a blank line, and finally the full poem. This code
-snippet combines that data and packages it into a MIMEText container,
-ready to be emailed.
+For my daily email, I want to see the title of the poem first, followed by the
+author, then a blank line, and finally the full poem. This code snippet combines
+that data and packages it into a MIMEText container, ready to be emailed.
#+begin_src python
msg_body = title + "\n" + author + "\n\n" + lines
msg = MIMEText(msg_body)
#+end_src
-Before we send the email, we need to prepare the metadata (subject,
-from, to, etc.):
+Before we send the email, we need to prepare the metadata (subject, from, to,
+etc.):
#+begin_src python
sender_email = '[email protected]'
@@ -151,10 +149,9 @@ msg['To'] = recipient_email
** Sending the Email
-Now that I have everything ready to be emailed, the last step is to
-simply connect to an SMTP server and send the email out to the
-recipients. In my case, I installed =mailutils= on Ubuntu and let my
-SMTP server be =localhost=.
+Now that I have everything ready to be emailed, the last step is to simply
+connect to an SMTP server and send the email out to the recipients. In my case,
+I installed =mailutils= on Ubuntu and let my SMTP server be =localhost=.
#+begin_src python
smtp_server = 'localhost'
@@ -165,9 +162,8 @@ s.quit()
* The Result!
-Instead of including a screenshot, I've copied the contents of the email
-that was delivered to my inbox below since I set this process up in
-plaintext format.
+Instead of including a screenshot, I've copied the contents of the email that
+was delivered to my inbox below since I set this process up in plaintext format.
#+begin_src txt
Date: Wed, 22 Jun 2022 14:37:19 +0000 (UTC)
@@ -200,16 +196,16 @@ Some, wise in show, more fools indeed than they.
* Scheduling the Daily Email
Last, but not least, is scheduling this Python script with =crontab=. To
-schedule a script to run daily, you can add it to the =crontab= file. To
-do this, open =crontab= in editing mode:
+schedule a script to run daily, you can add it to the =crontab= file. To do
+this, open =crontab= in editing mode:
#+begin_src sh
crontab -e
#+end_src
-In the file, simply paste the following snippet at the bottom of the
-file and ensure that the file path is correctly pointing to wherever you
-saved your Python script:
+In the file, simply paste the following snippet at the bottom of the file and
+ensure that the file path is correctly pointing to wherever you saved your
+Python script:
#+begin_src config
0 8 ** ** ** python3 /home/<your_user>/dailypoem/main.py