1
0
Fork 0
mirror of synced 2024-07-04 05:50:34 +12:00

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.
This commit is contained in:
OMEGARAZER 2023-02-01 14:18:20 -05:00
parent 8c293a4684
commit 730856934b
No known key found for this signature in database
GPG key ID: D89925310D306E35
3 changed files with 22 additions and 13 deletions

View file

@ -7,12 +7,14 @@ on:
- "**.md"
- ".markdown_style.rb"
- ".mdlrc"
- "scripts/"
pull_request:
branches: [ master, development ]
paths-ignore:
- "**.md"
- ".markdown_style.rb"
- ".mdlrc"
- "scripts/"
jobs:
test:

View file

@ -64,7 +64,7 @@ bdfr-download = "bdfr.__main__:cli_download"
line-length = 120
[tool.flake8]
exclude = ["scripts"]
exclude = ["scripts/tests"]
max-line-length = 120
show-source = true
statistics = true

View file

@ -1,6 +1,6 @@
#! /usr/bin/env python3.9
'''
This script takes a list of submission IDs from a file named "successfulids" created with the
#!/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.
@ -14,12 +14,18 @@ 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.
'''
"""
import praw
from pathlib import Path
try:
r= praw.Reddit(
import praw
import prawcore.exceptions
except ImportError:
print("Please install PRAW")
try:
reddit = praw.Reddit(
client_id="CLIENTID",
client_secret="CLIENTSECRET",
password="USERPASSWORD",
@ -27,14 +33,15 @@ try:
username="USERNAME",
)
with open("successfulids", "r") as f:
for item in f:
r.submission(id = item.strip()).unsave()
with Path("successfulids").open() as id_file:
for item in id_file:
reddit.submission(id=item.strip()).unsave()
except:
print("Something went wrong. Did you install PRAW? Did you change the user login fields?")
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!")