/reddit-daily

E-mail me the top day of subreddits

Primary LanguagePythonMIT LicenseMIT

Reddit Daily

My implementation of ferold/reddit-weekly.

I'm using prefect to:

  • elegantly handle task failures
  • retry HTTP requests
  • notify you of email failures
  • run this on a schedule

Setup

Firstly, go to reddit apps and register a new app. You'll need the personal use script id, and the secret. In case you aren't sure about the authentication process, read about it here. Next step is to create an email account. Currently, the script is using Gmail to log in, but there are plans (#3) to provide a way to plug-in a back-end that takes care of the emailing part.

Then, you need to generate your reddit's refresh token. The easiest way is to run this script. This token is used for authentication to get a reddit account's subreddits.

  1. Add the relevant secrets to ~/.prefect/config.toml, see the prefect docs for more info

You'll need an app email password for your email address. Here's how to get one for gmail.

You'll also need to install the Prefect slack app and register a webhook if you'd like the flow to be able to slack you if something goes wrong.

# config.toml
[cloud]
use_local_secrets = true

[context.secrets]
REDDIT_DAILY_EMAIL = "place email here"
REDDIT_DAILY_EMAIL_PASSWORD = "place email app password here"
REDDIT_DAILY_REFRESH_TOKEN = "place app refresh token here"
REDDIT_DAILY_APP_ID = "reddit app id goes here"
REDDIT_DAILY_APP_SECRET = "reddit app secret goes here"
SLACK_WEBHOOK_URL = "slack webhook url goes here"
SLACK_MESSAGE = "slack message goes here. If you have a {} in the string, the {} will be replaced with the FlowRun ID. Useful for adding a URL with the appropriate UUID to your message."

Running Locally

If you'd like to test this script locally, first install dependencies using pip.

pip install -r requirements.txt

To run the flow, we can use an ipython session.

ipython -i reddit_daily.py

Once the session is open:

In [1]: flow.run()

What it looks like

Screenshot of newsletter from r/programming:

reddit-weekly

License

This project is licensed under the MIT license. See LICENSE.