Skip to content

Instantly share code, notes, and snippets.

@patrickleweryharris
Last active July 23, 2022 17:12
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save patrickleweryharris/4374752c0051e1afe73470d6b002ec87 to your computer and use it in GitHub Desktop.
Save patrickleweryharris/4374752c0051e1afe73470d6b002ec87 to your computer and use it in GitHub Desktop.
"""
Delete all saved posts / comments on your reddit account with PRAW.
See: https://lewery.ca/automation/delete-all-saved-reddit-links
Needs Python 3+ and Praw 5.3.0
"""
import argparse
import praw
def create_parser():
"""Create command line argument parser"""
parser = argparse.ArgumentParser(description="")
parser.add_argument("client_id", metavar="CLIENT_ID",
help="client_id for PRAW")
parser.add_argument("client_secret", metavar="CLIENT_SECRET",
help="client_secret for PRAW")
parser.add_argument("password", metavar="PASSWORD",
help="Reddit password")
parser.add_argument("username", metavar="USERNAME",
help="Reddit username")
return parser
def run_praw(client_id, client_secret, password, username):
"""
Delete all saved reddit posts for username
CLIENT_ID and CLIENT_SECRET come from creating a developer app on reddit
"""
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 """
parser = create_parser()
args = parser.parse_args()
run_praw(args.client_id, args.client_secret, args.password, args.username)
if __name__ == "__main__":
main()
@BillyOgilvie
Copy link

BillyOgilvie commented Sep 23, 2018

Thank you for this! Python and APIs are new to me, but I managed to figure it out after setting my app to be a script app.

I tweaked the script slightly so that it prints the name of each saved post as it goes.


reddit = praw.Reddit(client_id='client_id',
                     client_secret='client_secret',
                     username='username',
                     password='password',
                     user_agent='my user agent')

saved = reddit.user.me().saved(limit=10000)
for s in saved:
  try:
    print('DELETING...'+s.title)
    s.unsave()
  except AttributeError as err:
    print(err)```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment