|
|
@ -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:
|
|
|
|
|
|
|
|
subreddit = reddit.subreddit(
|
|
|
|
|
|
|
|
re.sub(r"r\/", "", input("What subreddit would you like to pull from? "))
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
except ValueError:
|
|
|
|
|
|
|
|
subreddit = reddit.subreddit("askreddit")
|
|
|
|
|
|
|
|
print_substep("Subreddit not defined. Using AskReddit.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
threads = subreddit.hot(limit=25)
|
|
|
|
try:
|
|
|
|
submission = list(threads)[random.randrange(0, 25)]
|
|
|
|
if os.getenv("SUBMISSION_ID"):
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
print_substep("Subreddit not defined. Using AskReddit.")
|
|
|
|
|
|
|
|
submission = get_random_submission(reddit , "askreddit")
|
|
|
|
|
|
|
|
|
|
|
|
print_substep(f"Video will be: {submission.title} :thumbsup:")
|
|
|
|
print_substep(f"Video will be: {submission.title} :thumbsup:")
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
|
|