Fixed a couple of issues..

pull/125/head
Lewis Menelaws 3 years ago
parent 49da171b55
commit c6ab604c18

@ -11,12 +11,19 @@ from video_creation.screenshot_downloader import download_screenshots_of_reddit_
from video_creation.final_video import make_final_video from video_creation.final_video import make_final_video
from utils.loader import Loader from utils.loader import Loader
from dotenv import load_dotenv from dotenv import load_dotenv
console = Console() console = Console()
from dotenv import load_dotenv from dotenv import load_dotenv
import os, time, shutil import os, time, shutil
configured = True configured = True
REQUIRED_VALUES = ["REDDIT_CLIENT_ID","REDDIT_CLIENT_SECRET","REDDIT_USERNAME","REDDIT_PASSWORD", "OPACITY"] REQUIRED_VALUES = [
"REDDIT_CLIENT_ID",
"REDDIT_CLIENT_SECRET",
"REDDIT_USERNAME",
"REDDIT_PASSWORD",
"OPACITY",
]
print_markdown( print_markdown(
@ -30,68 +37,77 @@ If there is a .env file, check if the required variables are set. If not, print
""" """
client_id=os.getenv("REDDIT_CLIENT_ID") client_id = os.getenv("REDDIT_CLIENT_ID")
client_secret=os.getenv("REDDIT_CLIENT_SECRET") client_secret = os.getenv("REDDIT_CLIENT_SECRET")
username=os.getenv("REDDIT_USERNAME") username = os.getenv("REDDIT_USERNAME")
password=os.getenv("REDDIT_PASSWORD") password = os.getenv("REDDIT_PASSWORD")
reddit2fa=os.getenv("REDDIT_2FA") reddit2fa = os.getenv("REDDIT_2FA")
load_dotenv()
console.log("[bold green]Checking environment variables...") console.log("[bold green]Checking environment variables...")
time.sleep(1) time.sleep(1)
if not os.path.exists(".env"): if not os.path.exists(".env"):
shutil.copy(".env.template", ".env") shutil.copy(".env.template", ".env")
configured = False configured = False
console.log("[red] Your .env file is invalid, or was never created. Standby.") console.log("[red] Your .env file is invalid, or was never created. Standby.")
for val in REQUIRED_VALUES: for val in REQUIRED_VALUES:
print(os.getenv(val))
if val not in os.environ or not os.getenv(val): if val not in os.environ or not os.getenv(val):
console.log(f"[bold red]Missing Variable: \"{val}\"") console.log(f'[bold red]Missing Variable: "{val}"')
configured = False configured = False
console.log("[red]Looks like you need to set your Reddit credentials in the .env file. Please follow the instructions in the README.md file to set them up.") console.log(
time.sleep(0.5) "[red]Looks like you need to set your Reddit credentials in the .env file. Please follow the instructions in the README.md file to set them up."
console.log("[red]We can also launch the easy setup wizard. type yes to launch it, or no to quit the program.") )
setup_ask = input("Launch setup wizard? > ") time.sleep(0.5)
if setup_ask=="yes": console.log(
console.log("[bold green]Here goes nothing! Launching setup wizard...") "[red]We can also launch the easy setup wizard. type yes to launch it, or no to quit the program."
time.sleep(0.5) )
os.system("python3 setup.py") setup_ask = input("Launch setup wizard? > ")
else: if setup_ask == "yes":
if setup_ask=="no": console.log("[bold green]Here goes nothing! Launching setup wizard...")
console.print("[red]Exiting...") time.sleep(0.5)
time.sleep(0.5) os.system("python3 setup.py")
exit() else:
else: if setup_ask == "no":
console.print("[red]I don't understand that. Exiting...") console.print("[red]Exiting...")
time.sleep(0.5) time.sleep(0.5)
exit() exit()
else:
console.print("[red]I don't understand that. Exiting...")
exit() time.sleep(0.5)
exit()
exit()
try: try:
float(os.getenv("OPACITY")) float(os.getenv("OPACITY"))
except: except:
console.log(f"[red]Please ensure that OPACITY is set between 0 and 1 in your .env file") console.log(
f"[red]Please ensure that OPACITY is set between 0 and 1 in your .env file"
)
configured = False configured = False
exit() exit()
console.log("[bold green]Enviroment Variables are set! Continuing...") console.log("[bold green]Enviroment Variables are set! Continuing...")
load_dotenv()
length, number_of_comments = save_text_to_mp3(reddit_object) length, number_of_comments = save_text_to_mp3(reddit_object)
download_screenshots_of_reddit_posts(reddit_object, number_of_comments, os.getenv("THEME")) download_screenshots_of_reddit_posts(
reddit_object, number_of_comments, os.getenv("THEME")
)
download_background() download_background()
chop_background_video(length) chop_background_video(length)
final_video = make_final_video(number_of_comments) final_video = make_final_video(number_of_comments)
if configured: if configured:
reddit_object = get_subreddit_threads() reddit_object = get_subreddit_threads()
length, number_of_comments = save_text_to_mp3(reddit_object) length, number_of_comments = save_text_to_mp3(reddit_object)
download_screenshots_of_reddit_posts(reddit_object, number_of_comments, os.getenv("THEME", "light")) download_screenshots_of_reddit_posts(
reddit_object, number_of_comments, os.getenv("THEME", "light")
)
download_background() download_background()
chop_background_video(length) chop_background_video(length)
final_video = make_final_video(number_of_comments) final_video = make_final_video(number_of_comments)

@ -1,8 +1,11 @@
from rich import Console from rich.console import Console
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
console = Console() console = Console()
import os, random, praw, re import os, random, praw, re
def get_subreddit_threads(): def get_subreddit_threads():
global submission global submission
""" """
@ -39,7 +42,9 @@ def get_subreddit_threads():
# ! Prompt the user to enter a subreddit # ! Prompt the user to enter a subreddit
try: try:
subreddit = reddit.subreddit( subreddit = reddit.subreddit(
re.sub(r"r\/", "", input("What subreddit would you like to pull from? ")) re.sub(
r"r\/", "", input("What subreddit would you like to pull from? ")
)
) )
except ValueError: except ValueError:
subreddit = reddit.subreddit("askreddit") subreddit = reddit.subreddit("askreddit")
@ -56,14 +61,14 @@ def get_subreddit_threads():
content["comments"] = [] content["comments"] = []
for top_level_comment in submission.comments: for top_level_comment in submission.comments:
if not top_level_comment.stickied: if not top_level_comment.stickied:
content["comments"].append( content["comments"].append(
{ {
"comment_body": top_level_comment.body, "comment_body": top_level_comment.body,
"comment_url": top_level_comment.permalink, "comment_url": top_level_comment.permalink,
"comment_id": top_level_comment.id, "comment_id": top_level_comment.id,
} }
) )
except AttributeError as e: except AttributeError as e:
pass pass

Loading…
Cancel
Save