Merge pull request #440 from AsadHumayun/develop
chore: clarify `.env` variables, fix: `env.COMMENT_LENGTH_RANGE` throws errors if it includes a `str` instance
This commit is contained in:
4 files changed
+29
-31
No files matched your search
+9
-5
@@ -1,3 +1,4 @@
|
||||
# This can be found in the email that reddit sent you when you created the app
|
||||
REDDIT_CLIENT_ID=""
|
||||
REDDIT_CLIENT_SECRET=""
|
||||
|
||||
@@ -5,15 +6,18 @@ REDDIT_USERNAME=""
|
||||
REDDIT_PASSWORD=""
|
||||
|
||||
# Valid options are "yes" and "no"
|
||||
|
||||
# Whether or not 2FA is enabled on the reddit account. Default: "no"
|
||||
REDDIT_2FA=""
|
||||
|
||||
#If no, it will ask you a thread link to extract the thread, if yes it will randomize it.
|
||||
RANDOM_THREAD="yes"
|
||||
# If no, it will ask you a thread link to extract the thread, if yes it will randomize it. Default: "no"
|
||||
RANDOM_THREAD=""
|
||||
|
||||
# Valid options are "light" and "dark"
|
||||
# Valid options are "light" and "dark". Default: "light"
|
||||
THEME=""
|
||||
|
||||
# Enter a subreddit, e.g. "AskReddit"
|
||||
# Enter a subreddit, e.g. "AskReddit". If this isn't defined, you'll be asked when
|
||||
# the programme runs. Simply press Enter if you wish to use the default "AskReddit" subreddit when prompted.
|
||||
SUBREDDIT=""
|
||||
|
||||
# Filters the comments by range of lenght (min and max characters)
|
||||
@@ -21,7 +25,7 @@ SUBREDDIT=""
|
||||
# DO NOT INSERT ANY SPACES BETWEEN THE COMMA AND THE VALUES
|
||||
COMMENT_LENGTH_RANGE = "min,max"
|
||||
|
||||
# Range is 0 -> 1
|
||||
# Range is 0 -> 1. Default: "0.9"
|
||||
OPACITY="0.9"
|
||||
|
||||
# The absolute path of the folder where you want to save the final video
|
||||
|
||||
@@ -2,14 +2,13 @@
|
||||
# Main
|
||||
from utils.console import print_markdown
|
||||
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 dotenv import load_dotenv
|
||||
import os
|
||||
import time, os
|
||||
|
||||
console = Console()
|
||||
|
||||
@@ -22,7 +21,7 @@ REQUIRED_VALUES = [
|
||||
"OPACITY",
|
||||
]
|
||||
|
||||
#Banner may look bad or wrong in IDE/Text Editor, but looks perfect in CMD, BASH or ZSH
|
||||
# Banner may look bad or wrong in IDE/Text Editor, but looks perfect in CMD, BASH or ZSH
|
||||
banner = '''
|
||||
|
||||
██████╗░███████╗██████╗░██████╗░██╗████████╗ ██╗░░░██╗██╗██████╗░███████╗░█████╗░
|
||||
@@ -41,20 +40,15 @@ banner = '''
|
||||
|
||||
'''
|
||||
print(banner)
|
||||
|
||||
#Banner may look bad or wrong in IDE/Text Editor, but looks perfect in CMD, BASH or ZSH
|
||||
|
||||
time.sleep(.5)
|
||||
time.sleep(0.5)
|
||||
|
||||
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")
|
||||
@@ -68,13 +62,11 @@ load_dotenv()
|
||||
console.log("[bold green]Checking environment variables...")
|
||||
time.sleep(.5)
|
||||
|
||||
|
||||
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
|
||||
|
||||
+16
-14
@@ -2,14 +2,10 @@ from numpy import Infinity
|
||||
from rich.console import Console
|
||||
from utils.console import print_step, print_substep, print_markdown
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
import random
|
||||
import praw
|
||||
import re
|
||||
import os, random, praw, re
|
||||
|
||||
console = Console()
|
||||
|
||||
|
||||
def get_subreddit_threads():
|
||||
global submission
|
||||
"""
|
||||
@@ -49,7 +45,7 @@ def get_subreddit_threads():
|
||||
if os.getenv("SUBREDDIT"):
|
||||
subreddit = reddit.subreddit(re.sub(r"r\/", "", os.getenv("SUBREDDIT")))
|
||||
else:
|
||||
# ! Prompt the user to enter a subreddit
|
||||
# Prompt the user to enter a subreddit
|
||||
try:
|
||||
subreddit = reddit.subreddit(
|
||||
re.sub(
|
||||
@@ -64,17 +60,19 @@ def get_subreddit_threads():
|
||||
|
||||
threads = subreddit.hot(limit=25)
|
||||
submission = list(threads)[random.randrange(0, 25)]
|
||||
|
||||
print_substep(f"Video will be: {submission.title}")
|
||||
print("Getting video comments...")
|
||||
|
||||
upvotes=submission.score
|
||||
ratio=submission.upvote_ratio * 100
|
||||
num_comments=submission.num_comments
|
||||
upvotes = submission.score
|
||||
ratio = submission.upvote_ratio * 100
|
||||
num_comments = submission.num_comments
|
||||
|
||||
console.log(f"[bold green] Video will be: {submission.title} :thumbsup:")
|
||||
console.log(f"[bold blue] Thread has " + str(upvotes) + " upvotes")
|
||||
console.log(f"[bold blue] Thread has a upvote ratio of " + str(ratio) + "%")
|
||||
console.log(f"[bold blue] Thread has " + str(num_comments) + " comments")
|
||||
console.log("Getting video comments...")
|
||||
|
||||
|
||||
try:
|
||||
content["thread_url"] = submission.url
|
||||
@@ -84,8 +82,13 @@ def get_subreddit_threads():
|
||||
|
||||
for top_level_comment in submission.comments:
|
||||
COMMENT_LENGTH_RANGE = [0, Infinity]
|
||||
if os.getenv("COMMENT_LENGTH_RANGE"):
|
||||
COMMENT_LENGTH_RANGE = [int(i) for i in os.getenv("COMMENT_LENGTH_RANGE").split(",")]
|
||||
|
||||
# Ensure all values are numeric before attempting to cast
|
||||
if os.getenv("COMMENT_LENGTH_RANGE") and (False not in list(map(lambda arg: arg.isnumeric(), os.getenv("COMMENT_LENGTH_RANGE").split(",")))):
|
||||
try:
|
||||
COMMENT_LENGTH_RANGE = [int(i) for i in os.getenv("COMMENT_LENGTH_RANGE").split(",")]
|
||||
except TypeError:
|
||||
pass
|
||||
if COMMENT_LENGTH_RANGE[0] <= len(top_level_comment.body) <= COMMENT_LENGTH_RANGE[1]:
|
||||
if not top_level_comment.stickied:
|
||||
content["comments"].append(
|
||||
@@ -95,9 +98,8 @@ def get_subreddit_threads():
|
||||
"comment_id": top_level_comment.id,
|
||||
}
|
||||
)
|
||||
|
||||
except AttributeError:
|
||||
pass
|
||||
print_substep("Received AskReddit threads successfully.", style="bold green")
|
||||
|
||||
print_substep("Received AskReddit threads successfully.", style="bold green")
|
||||
return content
|
||||
@@ -92,7 +92,7 @@ if input("Are you sure you want to continue? > ").strip().casefold() != "yes":
|
||||
# Once they confirm, move on with the script.
|
||||
console.print("[bold green]Alright! Let's get started!")
|
||||
|
||||
print("\n")
|
||||
print()
|
||||
console.log("Ensure you have the following ready to enter:")
|
||||
console.log("[bold green]Reddit Client ID")
|
||||
console.log("[bold green]Reddit Client Secret")
|
||||
|
||||
Reference in new issue
Block a user