Skip to content

Instantly share code, notes, and snippets.

@robmusial
Forked from patrickleweryharris/delete_all.py
Last active May 24, 2022 02:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robmusial/e68f87488a30fd98dff3882c03577dc6 to your computer and use it in GitHub Desktop.
Save robmusial/e68f87488a30fd98dff3882c03577dc6 to your computer and use it in GitHub Desktop.
"""
Delete all saved posts and comments on your reddit account with PRAW.
Based on: https://lewery.ca/automation/delete-all-saved-reddit-links
This version has argparse removed to remove the command line options and they
are instead set here inside of the script. This solved two problems for me:
1. Reddit usernames can start with a "-" and argparse does not like that.
2. No more password in your shell history
Needs Python 3+ and Praw 5.3.0
client_id and client_secret are created on reddit as a locally installed
script at https://old.reddit.com/prefs/apps/
"""
import praw
username = ""
password = ""
client_id = ""
client_secret = ""
def run_praw(client_id, client_secret, password, username):
print(client_id, client_secret, username)
user_agent = "/u/{} delete all saved entries".format(username)
r = praw.Reddit(client_id=client_id, client_secret=client_secret,
password=password, username=username,
user_agent=user_agent)
saved = r.user.me().saved(limit=1000)
for s in saved:
try:
s.unsave()
except AttributeError as err:
print(err)
def main():
""" Run the program """
run_praw(client_id, client_secret, password, username)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment