Inspirational Quote Bot in Python
Everyone likes to open their inbox every morning and find a motivational quote to start their day. I wanted to create a function that collects quotes from an API and sends out to the recipients in a list assigned to the variable “to” (not shown here for privacy).
To start we import the necessary packages including the unused scheduler package in case you wanted to automated the execution time. Setting up the quote API, I saved the quotes in a json format after pulling them from the URL given below. The author & text are then selected and passed into the yagmail loop where the author and text are printed for visibility & saved as two variables.
To send an email, the user must create a email & configure the app password to provide the SMTP server through yagmail. I then pass all the preset variables into the email loop, watching for the edge case of a quote not having an author. Please view the code below for a full tutorial, the only sections missing are the recipients emails & the calling the function to run. Enjoy!