From f12f0da76d848895528698357c5ea2db58e6af34 Mon Sep 17 00:00:00 2001 From: owengaspard Date: Tue, 31 May 2022 16:21:43 -0500 Subject: [PATCH] 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. --- .env.template | 2 +- reddit/subreddit.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.env.template b/.env.template index c598b49..68044bf 100644 --- a/.env.template +++ b/.env.template @@ -2,5 +2,5 @@ REDDIT_CLIENT_ID="" REDDIT_CLIENT_SECRET="" REDDIT_USERNAME="" REDDIT_PASSWORD="" -ASK_EACH_TIME=TRUE +ASK_EACH_TIME="TRUE" SUBREDDIT="" \ No newline at end of file diff --git a/reddit/subreddit.py b/reddit/subreddit.py index c88220a..53477d5 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -22,16 +22,16 @@ def get_subreddit_threads(): password=os.getenv("REDDIT_PASSWORD"), ) - if os.getenv("ASK_EACH_TIME") == TRUE: + if os.getenv("ASK_EACH_TIME") == "TRUE": try: subreddit = reddit.subreddit(input("What subreddit would you like to pull from? ")) - except NameError: + except ValueError: subreddit = reddit.subreddit("askreddit") print_substep("Subreddit not defined. Using AskReddit.") else: try: subreddit = reddit.subreddit(os.getenv("SUBREDDIT")) - except NameError: + except ValueError: subreddit = reddit.subreddit("askreddit") print_substep("Subreddit not defined. Using AskReddit.")