A Python script that helps you manage your Reddit content history by providing various options to clean, edit, and delete posts and comments based on different criteria. The script includes features like age-based deletion, karma-based filtering, and keyword-based management.
- Delete posts and comments older than a specified number of days
- Remove comments with negative karma
- Clean up low-engagement comments (1 karma and no replies)
- Target specific subreddits for content cleanup
- Remove content containing specific keywords
- Dry run mode for testing changes before execution
- Configurable comment replacement text
- Detailed logging and backup system
- Excluded subreddits list to protect important content
- Keyword-based exclusion
- Configurable delay between operations to respect API limits
- Comprehensive error handling and logging
- Backup of deleted content
- Python 3.6 or higher
- PRAW (Python Reddit API Wrapper)
- pytz library for timezone handling
- Clone the repository:
git clone https://github.com/905timur/Reddit-Content-Cleaner.git
cd Reddit-Content-Cleaner
- Install required packages:
pip install praw pytz
-
Navigate to Reddit Apps Preferences.
-
Click "Create application" at the bottom of the repository.
-
Select "script".
-
Fill out the description, and both the URL and redirect URI fields (you can point both fields to this GitHub page).
-
Click "create app".
-
Once your app is created, you will see your client ID and client secret. Both are highlighted below:
Create a file named credentials.txt
in the script directory with the following format:
your_client_id
your_client_secret
your_reddit_username
your_reddit_password
The script uses a config.json
file for customization. It will be automatically created on first run with default values, or you can create it manually:
{
"replacement_text": ".",
"min_delay": 6,
"max_delay": 8,
"excluded_subreddits": ["AskScience", "PersonalFinance", "LegalAdvice", "programming"],
"excluded_keywords": ["important", "keep this", "legal document", "confidential"],
"backup_enabled": true,
"dry_run": false
}
Configuration options:
replacement_text
: Text to replace comments with before deletionmin_delay
: Minimum delay between operations in secondsmax_delay
: Maximum delay between operations in secondsexcluded_subreddits
: List of subreddits to exclude from deletionexcluded_keywords
: List of keywords that will prevent content deletionbackup_enabled
: Enable/disable content backupsdry_run
: Test mode that shows what would be deleted without actually deleting
Run the script using:
python RedditContentCleaner.py
-
Remove content older than x days
- Deletes all posts and comments older than the specified number of days
- Prompts for the number of days
- Respects excluded subreddits and keywords
-
Remove comments with negative karma
- Automatically finds and removes all comments with negative karma scores
- Useful for cleaning up controversial or downvoted comments
-
Remove comments with 1 karma and no replies
- Cleans up comments that haven't received any engagement
- Helps remove "orphaned" comments from your history
-
Remove all posts
- Deletes all posts from your Reddit history
-
Remove posts older than x days
- Deletes posts older than the specified number of days
-
Remove posts under x upvotes
- Deletes posts with a score below the specified threshold
-
Remove content from specific subreddit
- Target a specific subreddit for content cleanup
- Useful for removing history from particular communities
-
Remove content containing keyword
- Search and remove posts or comments containing specific words or phrases
- Case-insensitive matching
-
Edit configuration
- View current configuration settings
- Provides instructions for modifying the config.json file
-
Enable/Disable dry run
- Toggle test mode on/off
- Shows what would be deleted without actually deleting
- Useful for verifying settings before running cleanup
- Quit
- Safely exit the program
When enabled, the backup system creates a deleted_content.txt
file containing:
- Timestamp of deletion
- Content score
- Subreddit name
- Original content (post or comment)
- Separator line for easy reading
Example backup entry:
Timestamp: 2025-01-06 12:34:56+00:00
Score: 1
Subreddit: AskReddit
Content: Original content text here
--------------------------------------------------
The script maintains a content_cleaner.log
file with detailed operation logs including:
- Timestamp of operations
- Success/failure status
- Error messages if any
- Affected subreddits
- Random delay between 6-8 seconds between operations
- Configurable through min_delay and max_delay settings
- Helps prevent Reddit API rate limit issues
- Excluded subreddits list prevents accidental deletion of important content
- Keyword-based exclusion for protecting specific content
- Dry run mode for testing configuration changes
- Backup system for recovery if needed
The script includes comprehensive error handling for:
- API connection issues
- Authentication problems
- Rate limiting errors
- File system errors
- Invalid input validation
- Always run in dry run mode first when making configuration changes
- Keep backups enabled unless storage is a concern
- Start with longer delays if unsure about rate limiting
- Regularly update excluded subreddits list
- Check logs periodically for any issues
-
Authentication Errors
- Verify credentials.txt format
- Check Reddit API credentials
- Ensure account password is correct
-
Rate Limiting
- Increase min_delay and max_delay values
- Check for other scripts using same account
- Verify API usage limits
-
Missing Content
- Check excluded_subreddits list
- Verify excluded_keywords
- Review log file for errors
If you encounter issues:
- Check the log file for error messages
- Review configuration settings
- Verify Reddit API status
- Open an issue on this GitHub repository
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Submit a pull request
- Include tests for new features
- Update documentation as needed
This project is licensed under the MIT License.
- Integrated post clean up
- Added media backup
- Added configuration file support
- Implemented dry run mode
- Added subreddit-specific deletion
- Added keyword-based deletion
- Improved logging and backup system
- Added type hints and better error handling
- Converted to class-based structure
- Added randomized 6-8 second delay between deletions
- API rate limit improvements
- Moved credentials to external file
- Updated datetime handling for timezone support