|
|
|
@ -4,7 +4,7 @@ from utils.console import print_step, print_substep
|
|
|
|
|
import praw
|
|
|
|
|
import random
|
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
|
import os
|
|
|
|
|
from os import getenv, environ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def ascifi(text):
|
|
|
|
@ -26,25 +26,31 @@ def get_subreddit_threads():
|
|
|
|
|
|
|
|
|
|
content = {}
|
|
|
|
|
load_dotenv()
|
|
|
|
|
reddit = praw.Reddit(client_id=os.getenv("REDDIT_CLIENT_ID"), client_secret=os.getenv("REDDIT_CLIENT_SECRET"),
|
|
|
|
|
user_agent="Accessing AskReddit threads", username=os.getenv("REDDIT_USERNAME"),
|
|
|
|
|
password=os.getenv("REDDIT_PASSWORD"), )
|
|
|
|
|
reddit = praw.Reddit(client_id=getenv("REDDIT_CLIENT_ID"), client_secret=getenv("REDDIT_CLIENT_SECRET"),
|
|
|
|
|
user_agent="Accessing AskReddit threads", username=getenv("REDDIT_USERNAME"),
|
|
|
|
|
password=getenv("REDDIT_PASSWORD"), )
|
|
|
|
|
"""
|
|
|
|
|
Ask user for subreddit input
|
|
|
|
|
"""
|
|
|
|
|
if not os.getenv("SUBREDDIT"):
|
|
|
|
|
if not getenv("SUBREDDIT"):
|
|
|
|
|
subreddit = reddit.subreddit(
|
|
|
|
|
input("What subreddit would you like to pull from? ")) # if the env isnt set, ask user
|
|
|
|
|
else:
|
|
|
|
|
print_substep(f"Using subreddit: r/{os.getenv('SUBREDDIT')} from environment variable config")
|
|
|
|
|
print_substep(f"Using subreddit: r/{getenv('SUBREDDIT')} from environment variable config")
|
|
|
|
|
subreddit = reddit.subreddit(
|
|
|
|
|
os.getenv("SUBREDDIT")) # Allows you to specify in .env. Done for automation purposes.
|
|
|
|
|
getenv("SUBREDDIT")) # Allows you to specify in .env. Done for automation purposes.
|
|
|
|
|
|
|
|
|
|
threads = subreddit.hot(limit=25)
|
|
|
|
|
submission = list(threads)[random.randrange(0, 25)]
|
|
|
|
|
print_substep(f'subreddit thread is: {submission.title}\n(if you dont like this, you can change it by exiting and rerunning the program)')
|
|
|
|
|
if getenv('POST_ID'):
|
|
|
|
|
submission = reddit.submission(id=getenv('POST_ID'))
|
|
|
|
|
else:
|
|
|
|
|
threads = subreddit.hot(limit=25)
|
|
|
|
|
submission = list(threads)[random.randrange(0, 25)]
|
|
|
|
|
|
|
|
|
|
print(submission)
|
|
|
|
|
print_substep(
|
|
|
|
|
f'subreddit thread is: {submission.title}\n(if you dont like this, you can change it by exiting and rerunning the program)')
|
|
|
|
|
|
|
|
|
|
os.environ["VIDEO_TITLE"] = str(ascifi(submission.title))
|
|
|
|
|
environ["VIDEO_TITLE"] = str(ascifi(submission.title))
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
content["thread_url"] = submission.url
|
|
|
|
|