Last active
December 26, 2022 01:27
-
-
Save MagicalBlob/7d72f0b104527e8a9118b59414a0d9b0 to your computer and use it in GitHub Desktop.
ByeByeReddit.py - A quick script to delete Reddit comments/submissions given a list of IDs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import praw | |
# Create a Reddit instance | |
reddit = praw.Reddit( | |
user_agent="ByeByeReddit.py/1.0.0 by MagicalBlob", | |
client_id="CLIENT_ID", | |
client_secret="CLIENT_SECRET", | |
username="USERNAME", | |
password="PASSWORD", | |
) | |
reddit.validate_on_submit = True | |
# Check if the script is running in read-only mode | |
if reddit.read_only: | |
# Can't really remove anything if we're in read-only mode | |
print("Script is running in read-only mode. Exiting...") | |
exit() | |
# Load the comments file | |
with open("comments.txt", "r") as f: | |
# Read the file contents | |
comments_content = f.read() | |
# Split the file contents into a list of comment IDs | |
comment_ids = comments_content.split() | |
# Loop through the list of comment IDs | |
print("Removing comments...") | |
for comment_id in comment_ids: | |
# Get the comment with the ID | |
try: | |
comment = reddit.comment(id=comment_id) | |
# Print the comment ID and body | |
print("Comment ID: " + comment.id) | |
print("Comment Body: " + comment.body) | |
# Edit the comment to say "[REDACTED]" | |
try: | |
comment.edit("[REDACTED]") | |
print("Comment edited.") | |
except: | |
print( | |
"Unable to edit comment with ID " | |
+ comment.id | |
+ " (is it deleted?)." | |
) | |
# Delete the comment | |
try: | |
comment.delete() | |
print("Comment deleted.") | |
except: | |
print( | |
"Unable to delete comment with ID " + comment.id + ". Skipping..." | |
) | |
except: | |
print("Unable to get comment with ID " + comment_id + ". Skipping...") | |
# Load the posts file | |
with open("posts.txt", "r") as f: | |
# Read the file contents | |
posts_content = f.read() | |
# Split the file contents into a list of post IDs | |
post_ids = posts_content.split() | |
# Loop through the list of post IDs | |
print("Removing submissions...") | |
for post_id in post_ids: | |
# Get the post with the ID | |
try: | |
submission = reddit.submission(id=post_id) | |
# Print the post ID and body | |
print("Submission ID: " + submission.id) | |
print("Submission Title: " + submission.title) | |
# Delete the post | |
try: | |
submission.delete() | |
print("Submission deleted.") | |
except: | |
print( | |
"Unable to delete Submission with ID " | |
+ submission.id | |
+ ". Skipping..." | |
) | |
except: | |
print("Unable to get submission with ID " + post_id + ". Skipping...") | |
print("Done!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment