1
0
Fork 0
mirror of synced 2024-06-02 18:34:37 +12:00
bulk-downloader-for-reddit/scripts/unsaveposts.py
OMEGARAZER 730856934b
Update unsaveposts.py
Make some updates to the unsaveposts script and updated flake8 exclude now that there is a python script in the scripts directory.

Also added the scripts directory to actions test ignore as any changes in there shouldn't have any affect on the tests that are performed.
2023-02-01 14:18:20 -05:00

48 lines
1.6 KiB
Python

#!/usr/bin/env python3
"""
This script takes a list of submission IDs from a file named "successfulids" created with the
"extract_successful_ids.sh" script and unsaves them from your account. To make it work you must
fill in the username and password fields below. Make sure you keep the quotes around the fields.
You'll need to make a "user script" in your reddit profile to run this.
Go to https://old.reddit.com/prefs/apps/
Click on "Develop an app" at the bottom.
Make sure you select a "script" not a "web app."
Give it a random name. Doesn't matter.
You need to fill in the "Redirect URI" field with something so go ahead and put 127.0.0.0 in there.
Save it.
The client ID is the 14 character string under the name you gave your script.
It'll look like a bunch of random characters like this: pspYLwDoci9z_A
The client secret is the longer string next to "secret".
Replace those two fields below. Again keep the quotes around the fields.
"""
from pathlib import Path
try:
import praw
import prawcore.exceptions
except ImportError:
print("Please install PRAW")
try:
reddit = praw.Reddit(
client_id="CLIENTID",
client_secret="CLIENTSECRET",
password="USERPASSWORD",
user_agent="Unsave Posts",
username="USERNAME",
)
with Path("successfulids").open() as id_file:
for item in id_file:
reddit.submission(id=item.strip()).unsave()
except FileNotFoundError:
print("ID file not found")
except prawcore.exceptions.ResponseException:
print("Something went wrong. Did you change the user login fields?")
else:
print("Done! Thanks for playing!")