diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 927d70a..89e9961 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: diff --git a/pyproject.toml b/pyproject.toml index c88008d..dc265b5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 diff --git a/scripts/unsaveposts.py b/scripts/unsaveposts.py index c332520..a0fe9ef 100644 --- a/scripts/unsaveposts.py +++ b/scripts/unsaveposts.py @@ -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!") -