A Python bot that uses PRAW (Python Reddit API Wrapper) to fetch and track bans from Reddit subreddits. The bot maintains a history of previously seen bans and displays only newly discovered ones.
- 🔍 Fetches ban information from Reddit using PRAW
- 💾 Stores previously seen bans in JSON format
- 🆕 Identifies and displays only new bans
- 🛡️ Robust error handling and logging
- ⚙️ Configurable via environment variables
- 📝 Comprehensive logging to both file and console
- Python 3.7 or higher
- Reddit API credentials (Client ID, Client Secret)
- pip (Python package installer)
-
Clone the repository (or download the files):
git clone <repository-url> cd <repository-directory>
-
Install dependencies:
pip install -r requirements.txt
-
Set up Reddit API credentials:
- Go to https://www.reddit.com/prefs/apps
- Click "Create App" or "Create Another App"
- Choose "script" as the app type
- Note down your Client ID and Client Secret
-
Create a
.envfile in the project directory:touch .env
-
Add your Reddit credentials to
.env:REDDIT_CLIENT_ID=your_client_id_here REDDIT_CLIENT_SECRET=your_client_secret_here REDDIT_USER_AGENT=RedditBanTracker/1.0 by YourUsername
Run the bot with default subreddits:
python reddit_ban_tracker.pyFor more control, use the enhanced CLI interface:
python cli.py --help# Monitor default subreddits
python cli.py
# Monitor specific subreddits
python cli.py -s "announcements,help,askreddit"
# Set custom fetch limit
python cli.py --limit 100
# Use custom config and storage files
python cli.py --config mybot.env --storage my_bans.json
# Monitor askreddit with custom limit
python cli.py --subreddits askreddit --limit 50Alternatively, use the basic script directly:
python reddit_ban_tracker.py "subreddit1,subreddit2,subreddit3"The bot can be configured through the .env file:
| Variable | Required | Description |
|---|---|---|
REDDIT_CLIENT_ID |
Yes | Your Reddit app's Client ID |
REDDIT_CLIENT_SECRET |
Yes | Your Reddit app's Client Secret |
REDDIT_USER_AGENT |
Yes | User agent string for API requests |
The bot creates several files during operation:
banned_users.json: Stores the history of seen bansreddit_ban_tracker.log: Log file with detailed operation history
- Authentication: Connects to Reddit API using PRAW with your credentials
- Data Fetching: Attempts to fetch ban data from specified subreddits
- Storage: Loads previously seen bans from
banned_users.json - Comparison: Compares new data with stored data to identify new bans
- Display: Shows only the newly discovered bans
- Update: Saves updated ban data back to the JSON file
- Ban Lists: Accessing actual ban lists requires moderator permissions for the subreddit
- Public Data: If ban lists aren't accessible, the bot falls back to publicly available moderation log data
- Rate Limits: The bot respects Reddit's API rate limits automatically through PRAW
- This bot only accesses publicly available information or data you have permission to access
- Ban information is stored locally and not shared
- Use responsibly and in compliance with Reddit's Terms of Service
-
"Missing required environment variables"
- Ensure your
.envfile exists and contains all required variables - Check that variable names are spelled correctly
- Ensure your
-
"Cannot access ban list"
- This is normal if you don't have moderator permissions
- The bot will fall back to publicly available moderation data
-
"Error fetching from subreddit"
- Check that the subreddit name is spelled correctly
- Ensure the subreddit exists and is accessible
Enable detailed logging by checking the reddit_ban_tracker.log file:
tail -f reddit_ban_tracker.log==================================================
NEW BANS DETECTED: 2
==================================================
Subreddit: r/announcements
Action: banuser
Target: u/example_user1
Details: Spam violation
Moderator: AutoModerator
Date: 2024-01-15 14:30:25
------------------------------
Subreddit: r/help
Action: removepost
Target: u/example_user2
Details: Rule violation
Moderator: ModeratorName
Date: 2024-01-15 14:32:10
------------------------------
.
├── reddit_ban_tracker.py # Main bot script
├── cli.py # Enhanced CLI interface
├── test_bot.py # Test script for verification
├── requirements.txt # Python dependencies
├── .env # Configuration file (create this)
├── .env.example # Configuration template
├── banned_users.json # Ban history (created automatically)
├── reddit_ban_tracker.log # Log file (created automatically)
└── README.md # This file
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
This tool is for educational and monitoring purposes only. Users are responsible for complying with Reddit's Terms of Service and API guidelines. The bot should be used responsibly and ethically.