From 2054e92071d4fc4d91189bb2b62ae6f972d2fa63 Mon Sep 17 00:00:00 2001 From: Aeziak Date: Sun, 5 Jun 2022 13:09:39 +0200 Subject: [PATCH] Allow users to define custom reddit thread from .env or generate random one as usual --- .env.template | 5 ++++- reddit/subreddit.py | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.env.template b/.env.template index cab265e..36864fb 100644 --- a/.env.template +++ b/.env.template @@ -11,5 +11,8 @@ THEME="" # Enter a subreddit, e.g. "AskReddit" SUBREDDIT="" +# Enter a reddit thread URL, leave it blank to load a random one from the Subreddit +REDDITTHREAD="" + # Range is 0 -> 1 -OPACITY="0.9" +OPACITY="0.9" \ No newline at end of file diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 61c909d..39fff01 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -45,9 +45,14 @@ def get_subreddit_threads(): subreddit = reddit.subreddit("askreddit") print_substep("Subreddit not defined. Using AskReddit.") - threads = subreddit.hot(limit=25) - submission = list(threads)[random.randrange(0, 25)] + if os.getenv("REDDITTHREAD"): + submission = reddit.submission(url=os.getenv("REDDITTHREAD")) + else: + threads = subreddit.hot(limit=25) + submission = list(threads)[random.randrange(0, 25)] + print_substep(f"Video will be: {submission.title} :thumbsup:") + try: content["thread_url"] = submission.url