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
from prawcore.exceptions import (
OAuthException,
ResponseException,
RequestException
)
from rich.console import Console
from main import main
@ -81,20 +76,6 @@ def program_options():
KeyboardInterrupt,
):
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__":

@ -3,7 +3,14 @@ import os
import re
import praw
from prawcore.exceptions import (
OAuthException,
ResponseException,
RequestException,
BadRequest
)
from dotenv import load_dotenv
from rich.console import Console
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.
"""
console = Console()
global submission
load_dotenv()
if os.getenv("REDDIT_2FA", default="no").casefold() == "yes":
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("> ")
pw = os.getenv("REDDIT_PASSWORD")
@ -31,14 +40,27 @@ def get_subreddit_threads(subreddit_, thread_link_):
passkey = os.getenv("REDDIT_PASSWORD")
content = {}
reddit = praw.Reddit(
client_id=os.getenv("REDDIT_CLIENT_ID").strip(),
client_secret=os.getenv("REDDIT_CLIENT_SECRET").strip(),
user_agent="Accessing AskReddit threads",
username=os.getenv("REDDIT_USERNAME").strip(),
password=passkey.strip(),
)
try:
reddit = praw.Reddit(
client_id=os.getenv("REDDIT_CLIENT_ID").strip(),
client_secret=os.getenv("REDDIT_CLIENT_SECRET").strip(),
user_agent="Accessing AskReddit threads",
username=os.getenv("REDDIT_USERNAME").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

Loading…
Cancel
Save