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:
parent
8c293a4684
commit
730856934b
3 changed files with 22 additions and 13 deletions
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#! /usr/bin/env python3.9
|
||||
'''
|
||||
#!/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.
|
||||
|
@ -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!")
|
||||
|
||||
|
|
Loading…
Reference in a new issue