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"
|
- "**.md"
|
||||||
- ".markdown_style.rb"
|
- ".markdown_style.rb"
|
||||||
- ".mdlrc"
|
- ".mdlrc"
|
||||||
|
- "scripts/"
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ master, development ]
|
branches: [ master, development ]
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- "**.md"
|
- "**.md"
|
||||||
- ".markdown_style.rb"
|
- ".markdown_style.rb"
|
||||||
- ".mdlrc"
|
- ".mdlrc"
|
||||||
|
- "scripts/"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
|
|
|
@ -64,7 +64,7 @@ bdfr-download = "bdfr.__main__:cli_download"
|
||||||
line-length = 120
|
line-length = 120
|
||||||
|
|
||||||
[tool.flake8]
|
[tool.flake8]
|
||||||
exclude = ["scripts"]
|
exclude = ["scripts/tests"]
|
||||||
max-line-length = 120
|
max-line-length = 120
|
||||||
show-source = true
|
show-source = true
|
||||||
statistics = true
|
statistics = true
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#! /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
|
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
|
"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.
|
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.
|
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
|
It'll look like a bunch of random characters like this: pspYLwDoci9z_A
|
||||||
The client secret is the longer string next to "secret".
|
The client secret is the longer string next to "secret".
|
||||||
Replace those two fields below. Again keep the quotes around the fields.
|
Replace those two fields below. Again keep the quotes around the fields.
|
||||||
'''
|
"""
|
||||||
|
|
||||||
import praw
|
from pathlib import Path
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r= praw.Reddit(
|
import praw
|
||||||
|
import prawcore.exceptions
|
||||||
|
except ImportError:
|
||||||
|
print("Please install PRAW")
|
||||||
|
|
||||||
|
try:
|
||||||
|
reddit = praw.Reddit(
|
||||||
client_id="CLIENTID",
|
client_id="CLIENTID",
|
||||||
client_secret="CLIENTSECRET",
|
client_secret="CLIENTSECRET",
|
||||||
password="USERPASSWORD",
|
password="USERPASSWORD",
|
||||||
|
@ -27,14 +33,15 @@ try:
|
||||||
username="USERNAME",
|
username="USERNAME",
|
||||||
)
|
)
|
||||||
|
|
||||||
with open("successfulids", "r") as f:
|
with Path("successfulids").open() as id_file:
|
||||||
for item in f:
|
for item in id_file:
|
||||||
r.submission(id = item.strip()).unsave()
|
reddit.submission(id=item.strip()).unsave()
|
||||||
|
|
||||||
except:
|
except FileNotFoundError:
|
||||||
print("Something went wrong. Did you install PRAW? Did you change the user login fields?")
|
print("ID file not found")
|
||||||
|
|
||||||
|
except prawcore.exceptions.ResponseException:
|
||||||
|
print("Something went wrong. Did you change the user login fields?")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("Done! Thanks for playing!")
|
print("Done! Thanks for playing!")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue