diff --git a/GUI.py b/GUI.py index 90e37ae..bc41838 100644 --- a/GUI.py +++ b/GUI.py @@ -1,6 +1,7 @@ # Import the server module import http.server import webbrowser + # Set the hostname HOST = "localhost" # Set the port number @@ -9,15 +10,16 @@ PORT = 4000 # Define class to display the index page of the web server class PythonServer(http.server.SimpleHTTPRequestHandler): def do_GET(self): - if self.path == '/GUI': - self.path = 'index.html' + if self.path == "/GUI": + self.path = "index.html" return http.server.SimpleHTTPRequestHandler.do_GET(self) + # Declare object of the class webServer = http.server.HTTPServer((HOST, PORT), PythonServer) # Print the URL of the webserver, new =2 opens in a new tab print(f"Server started at http://{HOST}:{PORT}/GUI/") -webbrowser.open(f'http://{HOST}:{PORT}/GUI/', new = 2) +webbrowser.open(f"http://{HOST}:{PORT}/GUI/", new=2) print("Website opened in new tab") print("Press Ctrl+C to quit") try: @@ -27,4 +29,4 @@ except KeyboardInterrupt: # Stop the web server webServer.server_close() print("The server is stopped.") - exit() \ No newline at end of file + exit() diff --git a/TTS/pyttsx.py b/TTS/pyttsx.py index 06d27c5..b5ffb29 100644 --- a/TTS/pyttsx.py +++ b/TTS/pyttsx.py @@ -19,9 +19,7 @@ class pyttsx: if voice_id == "" or voice_num == "": voice_id = 2 voice_num = 3 - raise ValueError( - "set pyttsx values to a valid value, switching to defaults" - ) + raise ValueError("set pyttsx values to a valid value, switching to defaults") else: voice_id = int(voice_id) voice_num = int(voice_num) diff --git a/main.py b/main.py index 7e0ef02..8a0755d 100755 --- a/main.py +++ b/main.py @@ -40,6 +40,7 @@ print_markdown( ) checkversion(__VERSION__) + def main(POST_ID=None): reddit_object = get_subreddit_threads(POST_ID) global redditid diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 716a7fa..11b93af 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -1,5 +1,7 @@ import re +from prawcore.exceptions import ResponseException + from utils import settings import praw from praw.models import MoreComments @@ -29,14 +31,21 @@ def get_subreddit_threads(POST_ID: str): username = settings.config["reddit"]["creds"]["username"] if str(username).casefold().startswith("u/"): username = username[2:] - reddit = praw.Reddit( - client_id=settings.config["reddit"]["creds"]["client_id"], - client_secret=settings.config["reddit"]["creds"]["client_secret"], - user_agent="Accessing Reddit threads", - username=username, - passkey=passkey, - check_for_async=False, - ) + try: + reddit = praw.Reddit( + client_id=settings.config["reddit"]["creds"]["client_id"], + client_secret=settings.config["reddit"]["creds"]["client_secret"], + user_agent="Accessing Reddit threads", + username=username, + passkey=passkey, + check_for_async=False, + ) + except ResponseException as e: + match e.response.status_code: + case 401: + print("Invalid credentials - please check them in config.toml") + except: + print("Something went wrong...") # Ask user for subreddit input print_step("Getting subreddit threads...") @@ -57,9 +66,7 @@ def get_subreddit_threads(POST_ID: str): subreddit_choice = sub if str(subreddit_choice).casefold().startswith("r/"): # removes the r/ from the input subreddit_choice = subreddit_choice[2:] - subreddit = reddit.subreddit( - subreddit_choice - ) # Allows you to specify in .env. Done for automation purposes. + subreddit = reddit.subreddit(subreddit_choice) if POST_ID: # would only be called if there are multiple queued posts submission = reddit.submission(id=POST_ID) diff --git a/utils/console.py b/utils/console.py index 1518c27..6f99a41 100644 --- a/utils/console.py +++ b/utils/console.py @@ -118,4 +118,3 @@ def handle_input( console.print( "[red bold]" + err_message + "\nValid options are: " + ", ".join(map(str, options)) + "." ) - diff --git a/utils/version.py b/utils/version.py index 3042c0c..a8177cc 100644 --- a/utils/version.py +++ b/utils/version.py @@ -1,11 +1,16 @@ import requests from utils.console import print_step + def checkversion(__VERSION__): - response = requests.get("https://api.github.com/repos/elebumm/RedditVideoMakerBot/releases/latest") - latestversion = (response.json()["tag_name"]) + response = requests.get( + "https://api.github.com/repos/elebumm/RedditVideoMakerBot/releases/latest" + ) + latestversion = response.json()["tag_name"] if __VERSION__ == latestversion: print_step(f"You are using the newest version ({__VERSION__}) of the bot") return True else: - print_step(f"You are using an older version ({__VERSION__}) of the bot. Download the newest version ({latestversion}) from https://github.com/elebumm/RedditVideoMakerBot/releases/latest") \ No newline at end of file + print_step( + f"You are using an older version ({__VERSION__}) of the bot. Download the newest version ({latestversion}) from https://github.com/elebumm/RedditVideoMakerBot/releases/latest" + )