A small script that searches specified subreddits for posts from today containing certain keywords. Compiles all such posts and sends a mail to the user.
- Download & install Python3.
- Clone or download this repository.
- Navigate to this repository and run
pip install -r requirements.txt
- Get yourself a Reddit client ID and client secret. Refer this.
- Get yourself a Gmail app-specific password. Refer this.. If you don't use Gmail, you'll have to modify the code to use your mail server. Or just create a temporary account or something.
- Modify
sample_config.py
to use the stuff you got above. Also include the subreddits to search and the keywords you want to use. And of course enter the mail ID to send mails to. - Rename
sample_config.py
toconfig.py
. - Run the script:
python3 bot.py
- Enjoy your daily digest!
So obviously this makes sense only if you run it every day (Or you could always adapt the code for your own nefarious purposes). So how do you do that? Well you have a couple of options. The first is to set up a cron job (UNIX) or schedule a task (Windows) (Sorry Mac users, I dunno what the equivalent for you is). Or you can schedule it to run on a server everyday. Personally, I've scheduled it on PythonAnywhere. The free versions allows for exactly one such script to be scheduled.
Yup. Feel free to do anything with this script. Be sure to credit me/this repo though. And if you make something cool, do share it. :)
- Retrieves the 1000 (API limitation) most recent posts from a subreddit.
- Iterates through each post. 2.1. Checks if the post is within the past 24 hours. 2.2. Checks if any keywords are in the post's title. 2.3. If both conditions are met, saves the post information.
- Makes a nicely formatted message to mail.
- Sends the mail.
Laziness. There's a couple of subreddits that I follow only for posts related to certain topics but too lazy to look through them everyday. So might as well get a daily digest no?