Change AET var to string, NameError to ValueError

Python was giving errors with TRUE as a bool, so I changed it to a string. Giving an undefined name returned a different error than I put in the except, so I edited it and ran some tests which were successful. I will work on implementing something to detect if the subreddit exists and if it includes anything (e.g. special characters) which cannot be in subreddit names.
pull/4/head
owengaspard 3 years ago
parent b1e1d07c8b
commit f12f0da76d

@ -2,5 +2,5 @@ REDDIT_CLIENT_ID=""
REDDIT_CLIENT_SECRET="" REDDIT_CLIENT_SECRET=""
REDDIT_USERNAME="" REDDIT_USERNAME=""
REDDIT_PASSWORD="" REDDIT_PASSWORD=""
ASK_EACH_TIME=TRUE ASK_EACH_TIME="TRUE"
SUBREDDIT="" SUBREDDIT=""

@ -22,16 +22,16 @@ def get_subreddit_threads():
password=os.getenv("REDDIT_PASSWORD"), password=os.getenv("REDDIT_PASSWORD"),
) )
if os.getenv("ASK_EACH_TIME") == TRUE: if os.getenv("ASK_EACH_TIME") == "TRUE":
try: try:
subreddit = reddit.subreddit(input("What subreddit would you like to pull from? ")) subreddit = reddit.subreddit(input("What subreddit would you like to pull from? "))
except NameError: except ValueError:
subreddit = reddit.subreddit("askreddit") subreddit = reddit.subreddit("askreddit")
print_substep("Subreddit not defined. Using AskReddit.") print_substep("Subreddit not defined. Using AskReddit.")
else: else:
try: try:
subreddit = reddit.subreddit(os.getenv("SUBREDDIT")) subreddit = reddit.subreddit(os.getenv("SUBREDDIT"))
except NameError: except ValueError:
subreddit = reddit.subreddit("askreddit") subreddit = reddit.subreddit("askreddit")
print_substep("Subreddit not defined. Using AskReddit.") print_substep("Subreddit not defined. Using AskReddit.")

Loading…
Cancel
Save