moved the exceptions directly to the modules

pull/280/head
iaacornus 3 years ago
parent d78b0a0c1c
commit b05143e955
No known key found for this signature in database
GPG Key ID: 281739AE7252598C

@ -1,10 +1,5 @@
import argparse import argparse
from prawcore.exceptions import (
OAuthException,
ResponseException,
RequestException
)
from rich.console import Console from rich.console import Console
from main import main from main import main
@ -81,20 +76,6 @@ def program_options():
KeyboardInterrupt, KeyboardInterrupt,
): ):
print_substep("Error occured!", style="bold red") print_substep("Error occured!", style="bold red")
except OAuthException:
console.print(
"[bold red]There is something wrong with the .env file, kindly check:[/bold red]\n"
+ "1. ClientID\n"
+ "2. ClientSecret\n"
+ "3. If these variables are fine, kindly check other variables."
)
except (
RequestException,
ResponseException,
):
console.print(
"[bold red]Kindly check the kind of application created, it must be script.[/bold red]"
)
if __name__ == "__main__": if __name__ == "__main__":

@ -3,7 +3,14 @@ import os
import re import re
import praw import praw
from prawcore.exceptions import (
OAuthException,
ResponseException,
RequestException,
BadRequest
)
from dotenv import load_dotenv from dotenv import load_dotenv
from rich.console import Console
from utils.console import print_step, print_substep from utils.console import print_step, print_substep
@ -17,12 +24,14 @@ def get_subreddit_threads(subreddit_, thread_link_):
Returns a list of threads from the AskReddit subreddit. Returns a list of threads from the AskReddit subreddit.
""" """
console = Console()
global submission global submission
load_dotenv() load_dotenv()
if os.getenv("REDDIT_2FA", default="no").casefold() == "yes": if os.getenv("REDDIT_2FA", default="no").casefold() == "yes":
print( print(
"\nEnter your two-factor authentication code from your authenticator app.\n" "\nEnter your two-factor authentication code from your authenticator app.\n", end=" "
) )
code = input("> ") code = input("> ")
pw = os.getenv("REDDIT_PASSWORD") pw = os.getenv("REDDIT_PASSWORD")
@ -31,6 +40,7 @@ def get_subreddit_threads(subreddit_, thread_link_):
passkey = os.getenv("REDDIT_PASSWORD") passkey = os.getenv("REDDIT_PASSWORD")
content = {} content = {}
try:
reddit = praw.Reddit( reddit = praw.Reddit(
client_id=os.getenv("REDDIT_CLIENT_ID").strip(), client_id=os.getenv("REDDIT_CLIENT_ID").strip(),
client_secret=os.getenv("REDDIT_CLIENT_SECRET").strip(), client_secret=os.getenv("REDDIT_CLIENT_SECRET").strip(),
@ -38,7 +48,19 @@ def get_subreddit_threads(subreddit_, thread_link_):
username=os.getenv("REDDIT_USERNAME").strip(), username=os.getenv("REDDIT_USERNAME").strip(),
password=passkey.strip(), password=passkey.strip(),
) )
except (
OAuthException,
ResponseException,
RequestException,
BadRequest
):
console.print(
"[bold red]There is something wrong with the .env file, kindly check:[/bold red]\n"
+ "1. ClientID\n"
+ "2. ClientSecret\n"
+ "3. If these variables are fine, kindly check other variables."
+ "4. Check if the type of Reddit app created is script (personal use script)."
)
# If the user specifies that he doesnt want a random thread, or if # If the user specifies that he doesnt want a random thread, or if

Loading…
Cancel
Save