diff --git a/.env.template b/.env.template index 2e1ec9e..bcd326d 100644 --- a/.env.template +++ b/.env.template @@ -19,7 +19,7 @@ THEME="LIGHT" # used if you want to run multiple times. set to an int e.g. 4 or 29 and leave blank for 1 TIMES_TO_RUN="" # max number of characters a comment can have. -MAX_COMMENT_LENGTH="500" +MAX_COMMENT_LENGTH="500" # default is 500 # Range is 0 -> 1 recommended around 0.8-0.9 OPACITY="1" diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 34a8e17..7c5db91 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -15,6 +15,13 @@ def textify(text): return "".join(filter(TEXT_WHITELIST.__contains__, text)) +def try_env(param, backup): + try: + return environ[param] + except KeyError: + return backup + + def get_subreddit_threads(): """ Returns a list of threads from the AskReddit subreddit. @@ -89,7 +96,7 @@ def get_subreddit_threads(): if top_level_comment.body in ["[removed]", "[deleted]"]: continue # # see https://github.com/JasonLovesDoggo/RedditVideoMakerBot/issues/78 if not top_level_comment.stickied: - if len(top_level_comment.body) <= int(environ["MAX_COMMENT_LENGTH"]): + if len(top_level_comment.body) <= int(try_env("MAX_COMMENT_LENGTH", 500)): content["comments"].append( { "comment_body": top_level_comment.body,