From acb6017d5bc2c851ed97912565b5bf4e6b369ace Mon Sep 17 00:00:00 2001 From: Asad Date: Sat, 11 Jun 2022 01:01:16 +0100 Subject: [PATCH 1/5] chore(env): clarify definitions, include defaults --- .env.template | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.env.template b/.env.template index 5830840..f3a2fc8 100644 --- a/.env.template +++ b/.env.template @@ -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,17 @@ 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". SUBREDDIT="" # Filters the comments by range of lenght (min and max characters) @@ -21,7 +24,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 From 8472915cf912f34bddb7618b7c338711497c0d82 Mon Sep 17 00:00:00 2001 From: Asad Date: Sat, 11 Jun 2022 01:01:39 +0100 Subject: [PATCH 2/5] chore: remove debug statements and clean up --- main.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/main.py b/main.py index cade990..6b0e825 100644 --- a/main.py +++ b/main.py @@ -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,16 +21,13 @@ REQUIRED_VALUES = [ "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") @@ -45,13 +41,11 @@ 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 From f6be3d2f1a4111d965f0fb68019c4324e9abf2d6 Mon Sep 17 00:00:00 2001 From: Asad Date: Sat, 11 Jun 2022 01:09:34 +0100 Subject: [PATCH 3/5] fix(subreddit): Exception thrown if any value in `COMMENT_LENGTH_RANGE` is not numeric --- reddit/subreddit.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 40c95b6..bf9be74 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -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,7 +60,7 @@ 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...") @@ -76,8 +72,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( @@ -87,9 +88,9 @@ 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") + print(content["comments"]) return content From fc980a4a734807796c06339790eee1bb049cc9fb Mon Sep 17 00:00:00 2001 From: Asad Date: Sat, 11 Jun 2022 01:20:36 +0100 Subject: [PATCH 4/5] chore(env): clarify default value mapping for `SUBREDDIT` --- .env.template | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.env.template b/.env.template index f3a2fc8..2ff25d7 100644 --- a/.env.template +++ b/.env.template @@ -16,7 +16,8 @@ RANDOM_THREAD="" # 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) From a4e7963d511f75709518f814f86d3301a3608c55 Mon Sep 17 00:00:00 2001 From: Asad Date: Sat, 11 Jun 2022 01:36:24 +0100 Subject: [PATCH 5/5] remove debug statement --- reddit/subreddit.py | 1 - setup.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index bf9be74..6d002e6 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -92,5 +92,4 @@ def get_subreddit_threads(): pass print_substep("Received AskReddit threads successfully.", style="bold green") - print(content["comments"]) return content diff --git a/setup.py b/setup.py index b09c30d..640cd26 100755 --- a/setup.py +++ b/setup.py @@ -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")