NOTE: I still need to fine-tune the rate limiting, I don't do exponential back offs as it doesn't seem like its needed so if we hit a rate limit it will pause for 30 seconds and go again. Feel free to submit a PR to improve it!
A super cool Python script to monitor Reddit posts and comments for specified keywords using the PRAW (Python Reddit API Wrapper) and Aho-Corasick algorithm for efficient keyword matching. The script also provides aesthetic output using the Rich library.
Shout out to https://f5bot.com for the inspiration especially when using Aho-Corasick!
This project monitors Reddit for keywords in new submissions and comments in real time. It utilises the Aho-Corasick algorithm for fast keyword searching and the Rich library for beautiful console output. The script also supports graceful shutdown and handles Reddit's rate limits as both can ruin the vibe.
- Monitors multiple keywords in Reddit posts and comments.
- Utilises Aho-Corasick algorithm for efficient keyword matching.
- Handles Reddit API rate limits.
- Looks good doing it with the Rich library.
- Supports graceful shutdown on receiving a SIGINT signal (Ctrl+C).
-
Clone the repository:
git clone https://github.com/dansholds/menshun.git cd menshun
-
Create a virtual environment (optional but recommended):
python3 -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install the required dependencies:
pip3 install -r requirements.txt
-
Set up environment variables:
Create a
.env
file in the project directory with your Reddit app credentials:REDDIT_CLIENT_ID=your_client_id REDDIT_CLIENT_SECRET=your_client_secret REDDIT_USER_AGENT=your_user_agent
You can register a Reddit app to get these credentials at Reddit Apps. It's super quick and free!
-
Run the script:
python3 menshun.py --keywords keyword1 keyword2 keyword3
Replace
keyword1
,keyword2
,keyword3
, etc., with the actual keywords you want to monitor. -
Example command:
python3 menshun.py --keywords python programming reddit #(don't actually use reddit as a keyword unless you want your terminal slammed with crap lol)
-
Graceful shutdown:
To stop the script, press
Ctrl+C
. The script will handle the signal and shut down gracefully.
Contributions are welcome! Please follow these steps to contribute:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Make your changes.
- Commit your changes with a descriptive commit message.
- Push your changes to your fork.
- Create a pull request to the main repository.
- profit
This project is licensed under the MIT License. See the LICENSE file for details.
For any questions or suggestions, please contact:
- GitHub: dansholds
- X: https://x.com/grapplingdev