Last active
July 23, 2022 17:12
-
-
Save patrickleweryharris/4374752c0051e1afe73470d6b002ec87 to your computer and use it in GitHub Desktop.
Delete all saved reddit links: https://lewery.ca/automation/delete-all-saved-reddit-links
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
""" | |
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.