This is just a really simple script that I was testing. It will be used in a larger project.
It simply:
- Gets the RSS feed of multiple subreddits eg https://www.reddit.com/r/python/new/.json
- Grabs the ID of the newest thread
- Prints a message and performs an action when a newer thread appears
- Sleeps 5 seconds
- Repeats
This project is not pip installable
One or more subreddits can be monitored.
This is controlled via reddit_data.json
. It maps a name of a subreddit to the last id that was recorded.
By default the file should be named reddit_data.json
and be in the cwd.
This will be automatically rewritten when new data is found.
[
{
"last_id": null,
"name": "news"
},
{
"last_id": null,
"name": "aww"
}
]
SUBREDDIT_MONITOR_LOG
controls logging level egDEBUG
,INFO
,ERROR
SUBREDDIT_MONITOR_SLEEP
seconds to sleep before checking next subreddit eg5
,120
- Warning: Anything less than
5
may cause errors SUBREDDIT_MONITOR_DATA
absolute path to reddit data file eg/Users/foo.bar/Documents/reddit_data.json
This is just a sample project, so you should download the source code and modify it to fit your needs.
Logic is in subreddit_monitor/__main__.py
and you can simply modify _on_new_entry()
to get started.
Python 3.5 or 2.7
requests