From f51cbbce4d95a3427eb14f22fe59f6135052f5c0 Mon Sep 17 00:00:00 2001 From: Domiziano Scarcelli Date: Sun, 5 Jun 2022 11:10:03 +0200 Subject: [PATCH] The script asks the user for the thread link in the console --- .env.template | 5 ++--- reddit/subreddit.py | 13 ++++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.env.template b/.env.template index 25936d2..9385e68 100644 --- a/.env.template +++ b/.env.template @@ -12,6 +12,5 @@ SUBREDDIT="askReddit" THEME="" -# Link of the thread -# (e.g. https://www.reddit.com/r/memes/comments/sbr31o/discordggrmemes_the_official_rmemes_discord_server/) -THREAD_LINK="" \ No newline at end of file +#If no, it will ask you a thread link to extract the thread, if yes it will randomize it. +RANDOM_THREAD="no" \ No newline at end of file diff --git a/reddit/subreddit.py b/reddit/subreddit.py index c2f6547..b83b0e3 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -1,3 +1,6 @@ +from webbrowser import get + +from click import style from utils.console import print_markdown, print_step, print_substep import praw import random @@ -34,12 +37,12 @@ def get_subreddit_threads(): username=os.getenv("REDDIT_USERNAME"), password=passkey, ) - # If the user inserts a thread link, pick that one - if os.getenv("THREAD_LINK"): - + # If the user specifies that he doesnt want a random thread, or if he doesn't insert the "RANDOM_THREAD" variable at all, ask the thread link + if not os.getenv("RANDOM_THREAD") or os.getenv("RANDOM_THREAD") == "no": + print_substep("Insert the full thread link:", style="bold green") + thread_link = input() print_step(f"Getting the inserted thread...") - - thread_id = os.getenv("THREAD_LINK").split("/")[6] + thread_id = thread_link.split("/")[6] submission = reddit.submission(thread_id) else: # Otherwise, picks a random thread from the inserted subreddit