forked from elebumm/RedditVideoMakerBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
100 lines (85 loc) · 3.26 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Main
from utils.console import print_markdown
from utils.console import print_step
from utils.console import print_substep
from rich.console import Console
import time
from reddit.subreddit import get_subreddit_threads
from video_creation.background import download_background, chop_background_video
from video_creation.voices import save_text_to_mp3
from video_creation.screenshot_downloader import download_screenshots_of_reddit_posts
from video_creation.final_video import make_final_video
from utils.loader import Loader
from dotenv import load_dotenv
console = Console()
from dotenv import load_dotenv
import os, time, shutil
configured = True
REQUIRED_VALUES = [
"REDDIT_CLIENT_ID",
"REDDIT_CLIENT_SECRET",
"REDDIT_USERNAME",
"REDDIT_PASSWORD",
"OPACITY",
]
print_markdown(
"### Thanks for using this tool! [Feel free to contribute to this project on GitHub!](https://lewismenelaws.com) If you have any questions, feel free to reach out to me on Twitter or submit a GitHub issue."
)
"""
Load .env file if exists. If it doesnt exist, print a warning and launch the setup wizard.
If there is a .env file, check if the required variables are set. If not, print a warning and launch the setup wizard.
"""
client_id = os.getenv("REDDIT_CLIENT_ID")
client_secret = os.getenv("REDDIT_CLIENT_SECRET")
username = os.getenv("REDDIT_USERNAME")
password = os.getenv("REDDIT_PASSWORD")
reddit2fa = os.getenv("REDDIT_2FA")
load_dotenv()
console.log("[bold green]Checking environment variables...")
time.sleep(1)
if not os.path.exists(".env"):
configured = False
console.log("[red] Your .env file is invalid, or was never created. Standby.")
for val in REQUIRED_VALUES:
#print(os.getenv(val))
if val not in os.environ or not os.getenv(val):
console.log(f'[bold red]Missing Variable: "{val}"')
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."
)
time.sleep(0.5)
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? > ")
if setup_ask == "yes":
console.log("[bold green]Here goes nothing! Launching setup wizard...")
time.sleep(0.5)
os.system("python3 setup.py")
elif setup_ask == "no":
console.print("[red]Exiting...")
time.sleep(0.5)
exit()
else:
console.print("[red]I don't understand that. Exiting...")
time.sleep(0.5)
exit()
try:
float(os.getenv("OPACITY"))
except:
console.log(
f"[red]Please ensure that OPACITY is set between 0 and 1 in your .env file"
)
configured = False
exit()
console.log("[bold green]Enviroment Variables are set! Continuing...")
if configured:
reddit_object = get_subreddit_threads()
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_background()
chop_background_video(length)
final_video = make_final_video(number_of_comments)