The user can select thread

pull/296/head
Ahmad Mujahid 3 years ago
parent 718b005d07
commit f57cad9798

@ -8,8 +8,11 @@ REDDIT_2FA=""
# Valid options are "light" and "dark" # Valid options are "light" and "dark"
THEME="" THEME=""
# Enter either a SUBREDDIT to choose randomly from or SUBMISSION_ID but not both
# Enter a subreddit, e.g. "AskReddit" # Enter a subreddit, e.g. "AskReddit"
SUBREDDIT="" SUBREDDIT=""
# Enter submission id, e.g. "v4nt9m"
SUBMISSION_ID=""
# Range is 0 -> 1 # Range is 0 -> 1
OPACITY="0.9" OPACITY="0.9"

@ -1,7 +1,13 @@
from asyncio.windows_events import NULL
from utils.console import print_markdown, print_step, print_substep from utils.console import print_markdown, print_step, print_substep
from dotenv import load_dotenv from dotenv import load_dotenv
import os, random, praw, re import os, random, praw, re
def get_random_submission(reddit , subreddit_name):
subreddit = reddit.subreddit(re.sub(r"r\/", "", subreddit_name))
threads = subreddit.hot(limit=25)
return list(threads)[random.randrange(0, 25)]
def get_subreddit_threads(): def get_subreddit_threads():
global submission global submission
""" """
@ -10,8 +16,6 @@ def get_subreddit_threads():
load_dotenv() load_dotenv()
print_step("Getting AskReddit threads...")
if os.getenv("REDDIT_2FA", default="no").casefold() == "yes": if os.getenv("REDDIT_2FA", default="no").casefold() == "yes":
print( print(
"\nEnter your two-factor authentication code from your authenticator app.\n" "\nEnter your two-factor authentication code from your authenticator app.\n"
@ -33,20 +37,31 @@ def get_subreddit_threads():
password=passkey, password=passkey,
) )
if os.getenv("SUBREDDIT"): submission = NULL;
subreddit = reddit.subreddit(re.sub(r"r\/", "", os.getenv("SUBREDDIT")))
else:
# ! Prompt the user to enter a subreddit
try: try:
subreddit = reddit.subreddit( if os.getenv("SUBMISSION_ID"):
re.sub(r"r\/", "", input("What subreddit would you like to pull from? ")) print_step("Getting submissions from " + os.getenv("SUBMISSION_ID") + " based on .env file value")
) submission = reddit.submission(os.getenv("SUBMISSION_ID"))
elif os.getenv("SUBREDDIT"):
print_step("Getting a radon submission from " + os.getenv("SUBREDDIT") + " based on .env file value")
submission = get_random_submission(reddit , os.getenv("SUBREDDIT"))
else:
print_step("Choose your option : ")
print_substep("1: Enter subreddit to pull randomly from")
print_substep("2: Enter a submission to ID")
print_substep("3: Pull randomly from AskReddit")
option = int(input("Enter the option number : "))
if option == 1:
submission = get_random_submission(reddit , input("What subreddit would you like to pull from? "))
elif option == 2:
submission = reddit.submission(input("Enter submission ID : "));
else:
submission = get_random_submission(reddit , "askreddit")
except ValueError: except ValueError:
subreddit = reddit.subreddit("askreddit")
print_substep("Subreddit not defined. Using AskReddit.") print_substep("Subreddit not defined. Using AskReddit.")
submission = get_random_submission(reddit , "askreddit")
threads = subreddit.hot(limit=25)
submission = list(threads)[random.randrange(0, 25)]
print_substep(f"Video will be: {submission.title} :thumbsup:") print_substep(f"Video will be: {submission.title} :thumbsup:")
try: try:

Loading…
Cancel
Save