From f4b7ff736f60ba50c79fe8c2618ffc5dc5581933 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Wed, 1 Jun 2022 19:46:51 -0400 Subject: [PATCH 01/20] .gitignore: Add pycaches --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index a4589e5..3b9b9a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ assets/ +reddit/__pycache__/ +utils/__pycache__/ .env reddit-bot-351418-5560ebc49cac.json \ No newline at end of file From 39a691887eaec73c4fb41214ed906a37f7db5eb1 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Wed, 1 Jun 2022 20:44:54 -0400 Subject: [PATCH 02/20] Create setup TUI and improve overall UX --- main.py | 48 ++++++++++++++++++++++- reddit/askreddit.py | 7 +++- requirements.txt | 2 +- setup.py | 96 +++++++++++++++++++++++++++++++++++++++++++++ utils/loader.py | 53 +++++++++++++++++++++++++ 5 files changed, 202 insertions(+), 4 deletions(-) create mode 100644 setup.py create mode 100644 utils/loader.py diff --git a/main.py b/main.py index 8fb3d50..7e16291 100644 --- a/main.py +++ b/main.py @@ -1,15 +1,61 @@ +# 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 +import os from reddit.askreddit import get_askreddit_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() 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") + +console.log("[bold green]Checking environment variables...") +time.sleep(1) + +if client_id == "" or client_secret == "" or username == "" or password == "": + + 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") + else: + if 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() + + + exit() + +console.log("[bold green]Enviroment Variables are set! Continuing...") time.sleep(3) diff --git a/reddit/askreddit.py b/reddit/askreddit.py index 7c7110a..42afab4 100644 --- a/reddit/askreddit.py +++ b/reddit/askreddit.py @@ -1,9 +1,10 @@ +from rich import Console from utils.console import print_markdown, print_step, print_substep import praw import random from dotenv import load_dotenv import os - +console = Console() def get_askreddit_threads(): """ @@ -14,6 +15,7 @@ def get_askreddit_threads(): content = {} load_dotenv() + console.log("Logging in to reddit...") reddit = praw.Reddit( client_id=os.getenv("REDDIT_CLIENT_ID"), client_secret=os.getenv("REDDIT_CLIENT_SECRET"), @@ -25,6 +27,7 @@ def get_askreddit_threads(): threads = askreddit.hot(limit=25) submission = list(threads)[random.randrange(0, 25)] print_substep(f"Video will be: {submission.title} :thumbsup:") + console.log("Getting video comments...") try: content["thread_url"] = submission.url @@ -43,4 +46,4 @@ def get_askreddit_threads(): except AttributeError as e: pass print_substep("Received AskReddit threads Successfully.", style="bold green") - return content + return content \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index da87ca9..e90970b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -34,7 +34,7 @@ rich==12.4.4 six==1.16.0 toml==0.10.1 tqdm==4.64.0 -typed-ast==1.4.1 +typed-ast==1.5.4 # Please see issue https://github.com/elebumm/RedditVideoMakerBot/issues/16 comment three. typing_extensions==4.2.0 update-checker==0.18.0 urllib3==1.26.9 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..8214f72 --- /dev/null +++ b/setup.py @@ -0,0 +1,96 @@ +""" + +Setup Script for RedditVideoMakerBot + +""" + +# Imports +import os +import time +from utils.console import print_markdown +from utils.console import print_step +from utils.console import print_substep +from rich.console import Console +from utils.loader import Loader +console = Console() + +# These lines ensure the user: +# - knows they are in setup mode +# - knows that they are about to erase any other setup files/data. + +print_step("Setup Assistant") + +print_markdown( + "### You're in the setup wizard. Ensure you're supposed to be here, then type yes to continue. If you're not sure, type no to quit." +) + +# This Input is used to ensure the user is sure they want to continue. +ensureSetupIsRequired = input("Are you sure you want to continue? > ") +if ensureSetupIsRequired != "yes": + console.print("[red]Exiting...") + time.sleep(0.5) + exit() +else: + # Again, let them know they are about to erase all other setup data. + console.print("[bold red] This will overwrite your current settings. Are you sure you want to continue? [bold green]yes/no") + overwriteSettings = input("Are you sure you want to continue? > ") + if overwriteSettings != "yes": + console.print("[red]Abort mission! Exiting...") + time.sleep(0.5) + exit() + else: + # Once they confirm, move on with the script. + console.print("[bold green]Alright! Let's get started!") + time.sleep(1) + +console.log("Ensure you have the following ready to enter:") +console.log("[bold green]Reddit Client ID") +console.log("[bold green]Reddit Client Secret") +console.log("[bold green]Reddit Username") +console.log("[bold green]Reddit Password") +time.sleep(0.5) +console.print("[green]If you don't have these, please follow the instructions in the README.md file to set them up.") +console.print("[green]If you do have these, type yes to continue. If you dont, go ahead and grab those quickly and come back.") +confirmUserHasCredentials = input("Are you sure you have the credentials? > ") +if confirmUserHasCredentials != "yes": + console.print("[red]I don't understand that.") + console.print("[red]Exiting...") + exit() +else: + console.print("[bold green]Alright! Let's get started!") + time.sleep(1) + +""" + +Begin the setup process. + +""" + +console.log("Enter your credentials now.") +cliID = input("Client ID > ") +cliSec = input("Client Secret > ") +user = input("Username > ") +passw = input("Password > ") +console.log("Attempting to save your credentials...") +loader = Loader("Saving Credentials...", "Done!").start() + # you can also put a while loop here, e.g. while VideoIsBeingMade == True: ... +time.sleep(0.5) +console.log("Removing old .env file...") +os.remove(".env") +time.sleep(0.5) +console.log("Creating new .env file...") +with open('.env', 'a') as f: + f.write(f'REDDIT_CLIENT_ID="{cliID}"\n') + time.sleep(0.5) + f.write(f'REDDIT_CLIENT_SECRET="{cliSec}"\n') + time.sleep(0.5) + f.write(f'REDDIT_USERNAME="{user}"\n') + time.sleep(0.5) + f.write(f'REDDIT_PASSWORD="{passw}"\n') + +loader.stop() + +console.log("[bold green]Setup Complete! Returning...") + +# Post-Setup: send message and try to run main.py again. +os.system("python3 main.py") \ No newline at end of file diff --git a/utils/loader.py b/utils/loader.py new file mode 100644 index 0000000..58fd662 --- /dev/null +++ b/utils/loader.py @@ -0,0 +1,53 @@ +""" + +Okay, have to admit. This code is from StackOverflow. It's so efficient, that it's probably the best way to do it. +Although, it is edited to use less threads. + +""" +from itertools import cycle +from shutil import get_terminal_size +from threading import Thread +from time import sleep + + +class Loader: + def __init__(self, desc="Loading...", end="Done!", timeout=0.1): + """ + A loader-like context manager + + Args: + desc (str, optional): The loader's description. Defaults to "Loading...". + end (str, optional): Final print. Defaults to "Done!". + timeout (float, optional): Sleep time between prints. Defaults to 0.1. + """ + self.desc = desc + self.end = end + self.timeout = timeout + + self._thread = Thread(target=self._animate, daemon=True) + self.steps = ["⢿", "⣻", "⣽", "⣾", "⣷", "⣯", "⣟", "⡿"] + self.done = False + + def start(self): + self._thread.start() + return self + + def _animate(self): + for c in cycle(self.steps): + if self.done: + break + print(f"\r{self.desc} {c}", flush=True, end="") + sleep(self.timeout) + + def __enter__(self): + self.start() + + def stop(self): + self.done = True + cols = get_terminal_size((80, 20)).columns + print("\r" + " " * cols, end="", flush=True) + print(f"\r{self.end}", flush=True) + + def __exit__(self, exc_type, exc_value, tb): + # handle exceptions with those variables ^ + self.stop() \ No newline at end of file From 74363f021e73a3cad3ee7d0a2f229d2915a27607 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Wed, 1 Jun 2022 20:48:26 -0400 Subject: [PATCH 03/20] README Updates --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 26d8156..3b3acce 100644 --- a/README.md +++ b/README.md @@ -31,10 +31,12 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p ## Installation 👩‍💻 1. Clone this repository -2. Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` files. -3. Run `pip3 install -r requirements.txt` -4. Run `python3 main.py` -5. ... +2. Run `pip3 install -r requirements.txt` +3. + 2a. **Automatic Setup** Run `python3 main.py`, it will automatically detect that you do not have variables set + 2b. **Manual Setup** Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` files. + +4. (only if you did manual setup) Run `python3 main.py` 6. Enjoy 😎 ## Contributing & Ways to improve 📈 From 1e42fd2a3d6ccdfecf620e1c206273149b5f2d26 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Wed, 1 Jun 2022 20:49:23 -0400 Subject: [PATCH 04/20] make readme look better --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3b3acce..708b5ad 100644 --- a/README.md +++ b/README.md @@ -33,8 +33,8 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 1. Clone this repository 2. Run `pip3 install -r requirements.txt` 3. - 2a. **Automatic Setup** Run `python3 main.py`, it will automatically detect that you do not have variables set - 2b. **Manual Setup** Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` files. + 2a. **Automatic Setup**: Run `python3 main.py`, it will automatically detect that you do not have variables set + 2b. **Manual Setup**: Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` files. 4. (only if you did manual setup) Run `python3 main.py` 6. Enjoy 😎 From 3c4eac42c097a7c4fe7a54cab6699ae325052fdd Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Wed, 1 Jun 2022 20:49:46 -0400 Subject: [PATCH 05/20] maybe a *little* bit better --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 708b5ad..82d047d 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 2. Run `pip3 install -r requirements.txt` 3. 2a. **Automatic Setup**: Run `python3 main.py`, it will automatically detect that you do not have variables set + 2b. **Manual Setup**: Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` files. 4. (only if you did manual setup) Run `python3 main.py` From e4ed7aa69e75538e194d6e75b4cc5e409cd62806 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Wed, 1 Jun 2022 20:51:01 -0400 Subject: [PATCH 06/20] Clarification for setup. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 82d047d..6369b4f 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 1. Clone this repository 2. Run `pip3 install -r requirements.txt` 3. - 2a. **Automatic Setup**: Run `python3 main.py`, it will automatically detect that you do not have variables set + 2a. **Automatic Setup**: Run `python3 main.py` and type "yes" where it says "Setup Wizard". The Setup Wizard will guide you through the setup process. 2b. **Manual Setup**: Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` files. From e03f52988837745f3c583d31525fb6f6132f08b4 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Wed, 1 Jun 2022 20:55:20 -0400 Subject: [PATCH 07/20] README: got some of the stages mixed up. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6369b4f..8e7eec7 100644 --- a/README.md +++ b/README.md @@ -33,9 +33,9 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 1. Clone this repository 2. Run `pip3 install -r requirements.txt` 3. - 2a. **Automatic Setup**: Run `python3 main.py` and type "yes" where it says "Setup Wizard". The Setup Wizard will guide you through the setup process. + 3a. **Automatic Setup**: Run `python3 main.py` and type "yes" where it says "Setup Wizard". The Setup Wizard will guide you through the setup process. - 2b. **Manual Setup**: Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` files. + 3b. **Manual Setup**: Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` files. 4. (only if you did manual setup) Run `python3 main.py` 6. Enjoy 😎 From 16664e010a8d57a89acef3ad576143e8580c8330 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Thu, 2 Jun 2022 13:11:10 -0400 Subject: [PATCH 08/20] Reviews: Various Changes --- main.py | 2 +- setup.py | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 7e16291..2c026ae 100644 --- a/main.py +++ b/main.py @@ -32,7 +32,7 @@ password=os.getenv("REDDIT_PASSWORD") console.log("[bold green]Checking environment variables...") time.sleep(1) -if client_id == "" or client_secret == "" or username == "" or password == "": +if not all(client_id, client_secret, username, password): 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) diff --git a/setup.py b/setup.py index 8214f72..7e4521f 100644 --- a/setup.py +++ b/setup.py @@ -12,8 +12,15 @@ from utils.console import print_step from utils.console import print_substep from rich.console import Console from utils.loader import Loader +from os.path import exists console = Console() +setup_done = exists(".setup-done-before") + +if setup_done == True: + console.log("[red]Setup was already completed! Please make sure you have to run this script again. If you have to, please delete the file .setup-done-before") + exit() + # These lines ensure the user: # - knows they are in setup mode # - knows that they are about to erase any other setup files/data. @@ -25,7 +32,7 @@ print_markdown( ) # This Input is used to ensure the user is sure they want to continue. -ensureSetupIsRequired = input("Are you sure you want to continue? > ") +ensureSetupIsRequired = input("Are you sure you want to continue? > ").casefold() if ensureSetupIsRequired != "yes": console.print("[red]Exiting...") time.sleep(0.5) @@ -33,7 +40,7 @@ if ensureSetupIsRequired != "yes": else: # Again, let them know they are about to erase all other setup data. console.print("[bold red] This will overwrite your current settings. Are you sure you want to continue? [bold green]yes/no") - overwriteSettings = input("Are you sure you want to continue? > ") + overwriteSettings = input("Are you sure you want to continue? > ").casefold() if overwriteSettings != "yes": console.print("[red]Abort mission! Exiting...") time.sleep(0.5) @@ -51,7 +58,7 @@ console.log("[bold green]Reddit Password") time.sleep(0.5) console.print("[green]If you don't have these, please follow the instructions in the README.md file to set them up.") console.print("[green]If you do have these, type yes to continue. If you dont, go ahead and grab those quickly and come back.") -confirmUserHasCredentials = input("Are you sure you have the credentials? > ") +confirmUserHasCredentials = input("Are you sure you have the credentials? > ").casefold() if confirmUserHasCredentials != "yes": console.print("[red]I don't understand that.") console.print("[red]Exiting...") @@ -88,6 +95,9 @@ with open('.env', 'a') as f: time.sleep(0.5) f.write(f'REDDIT_PASSWORD="{passw}"\n') +with open('.setup-done-before', 'a') as f: + f.write("This file blocks the setup assistant from running again. Delete this file to run setup again.") + loader.stop() console.log("[bold green]Setup Complete! Returning...") From 52302cc42d7e399ccfaf47c94f37381f32fadfb9 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Thu, 2 Jun 2022 16:09:47 -0400 Subject: [PATCH 09/20] gitignore - new files --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3b9b9a4..d6b5611 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ assets/ reddit/__pycache__/ utils/__pycache__/ .env -reddit-bot-351418-5560ebc49cac.json \ No newline at end of file +reddit-bot-351418-5560ebc49cac.json +video_creation/__pycache__/ +.setup-done-before \ No newline at end of file From 4506339e21f673e911f8f5badaee4d20d53c1c07 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Thu, 2 Jun 2022 16:16:15 -0400 Subject: [PATCH 10/20] ACCEPT: Incoming Change (main.py) --- main.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/main.py b/main.py index f1782b2..498d78f 100644 --- a/main.py +++ b/main.py @@ -4,15 +4,8 @@ from utils.console import print_step from utils.console import print_substep from rich.console import Console import time -<<<<<<< HEAD import os -from reddit.askreddit import get_askreddit_threads -||||||| 5b39896 -from reddit.askreddit import get_askreddit_threads -======= - from reddit.subreddit import get_subreddit_threads ->>>>>>> 6fc5d2a7377dfe9f65d0d011fc260602527847c9 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 d8def59e5d583071c47eb89cbf86241574eb2808 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Thu, 2 Jun 2022 16:17:48 -0400 Subject: [PATCH 11/20] ACCEPT: Incoming change. (README.md) --- README.md | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/README.md b/README.md index 05ae2df..1dbec21 100644 --- a/README.md +++ b/README.md @@ -31,29 +31,12 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p ## Installation 👩‍💻 1. Clone this repository -<<<<<<< HEAD -2. Run `pip3 install -r requirements.txt` -3. - 3a. **Automatic Setup**: Run `python3 main.py` and type "yes" where it says "Setup Wizard". The Setup Wizard will guide you through the setup process. - - 3b. **Manual Setup**: Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` files. - -4. (only if you did manual setup) Run `python3 main.py` -6. Enjoy 😎 -||||||| 5b39896 -2. Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` files. -3. Run `pip3 install -r requirements.txt` -4. Run `python3 main.py` -5. ... -6. Enjoy 😎 -======= 2. Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` file, along with whether your account uses two-factor authentication. 3. Run `pip3 install -r requirements.txt` 4. Run `playwright install` and `playwright install-deps`. 5. Run `python3 main.py` 6. ... 7. Enjoy 😎 ->>>>>>> 6fc5d2a7377dfe9f65d0d011fc260602527847c9 ## Contributing & Ways to improve 📈 @@ -65,4 +48,4 @@ I have tried to simplify the code so anyone can read it and start contributing a - [ ] Allowing users to choose a background that is picked instead of the Minecraft one. - [x] Allowing users to choose between any subreddit. - [ ] Allowing users to change voice. -- [ ] Creating better documentation and adding a command line interface. +- [ ] Creating better documentation and adding a command line interface. \ No newline at end of file From b1c98726eb8389553c78882717877b7cc28251ed Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Thu, 2 Jun 2022 16:20:35 -0400 Subject: [PATCH 12/20] README: Automatic install --- README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1dbec21..630cca4 100644 --- a/README.md +++ b/README.md @@ -31,10 +31,14 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p ## Installation 👩‍💻 1. Clone this repository -2. Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` file, along with whether your account uses two-factor authentication. -3. Run `pip3 install -r requirements.txt` -4. Run `playwright install` and `playwright install-deps`. -5. Run `python3 main.py` +2. Run `pip3 install -r requirements.txt` +3. Run `playwright install` and `playwright install-deps`. +4. + 4a **Automatic Install**: Run `python3 main.py` and type 'yes' to activate the setup assistant. + + 4b **Manual Install**: Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` file, along with whether your account uses two-factor authentication. + +5. Run `python3 main.py` (unless you chose automatic install, then the installer will automatically run main.py) 6. ... 7. Enjoy 😎 From 3b26c0e282fd3e9cbd344fb154d6c5034c0310fa Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Thu, 2 Jun 2022 16:22:07 -0400 Subject: [PATCH 13/20] main.py: Add REDDIT_2FA to env variable check. --- main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.py b/main.py index 498d78f..07f2f13 100644 --- a/main.py +++ b/main.py @@ -28,6 +28,8 @@ 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") + console.log("[bold green]Checking environment variables...") time.sleep(1) From e18bb1229ac19f166389c67cbc6e4ef361b9e058 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Thu, 2 Jun 2022 16:23:09 -0400 Subject: [PATCH 14/20] REQUIREMENTS.TXT: Accept Incoming Change --- requirements.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/requirements.txt b/requirements.txt index 6ae7cfe..59dc596 100644 --- a/requirements.txt +++ b/requirements.txt @@ -35,13 +35,7 @@ rich==12.4.4 six==1.16.0 toml==0.10.1 tqdm==4.64.0 -<<<<<<< HEAD -typed-ast==1.5.4 # Please see issue https://github.com/elebumm/RedditVideoMakerBot/issues/16 comment three. -||||||| 5b39896 -typed-ast==1.4.1 -======= typed-ast==1.5.4 ->>>>>>> 6fc5d2a7377dfe9f65d0d011fc260602527847c9 typing_extensions==4.2.0 update-checker==0.18.0 urllib3==1.26.9 From 51d561bc3e479bd6cb5b5791411a6459b028d4d2 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Thu, 2 Jun 2022 16:25:39 -0400 Subject: [PATCH 15/20] Removed an extra line in main.py; added 2fa to setup.py --- main.py | 2 +- setup.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 07f2f13..1882039 100644 --- a/main.py +++ b/main.py @@ -67,4 +67,4 @@ length, number_of_comments = save_text_to_mp3(reddit_object) download_screenshots_of_reddit_posts(reddit_object, number_of_comments) download_background() chop_background_video(length) -final_video = make_final_video(number_of_comments) +final_video = make_final_video(number_of_comments) \ No newline at end of file diff --git a/setup.py b/setup.py index 7e4521f..f49b03b 100644 --- a/setup.py +++ b/setup.py @@ -55,6 +55,7 @@ console.log("[bold green]Reddit Client ID") console.log("[bold green]Reddit Client Secret") console.log("[bold green]Reddit Username") console.log("[bold green]Reddit Password") +console.log("[bold green]Reddit 2FA (yes or no)") time.sleep(0.5) console.print("[green]If you don't have these, please follow the instructions in the README.md file to set them up.") console.print("[green]If you do have these, type yes to continue. If you dont, go ahead and grab those quickly and come back.") @@ -78,6 +79,7 @@ cliID = input("Client ID > ") cliSec = input("Client Secret > ") user = input("Username > ") passw = input("Password > ") +twofactor = input("2fa Enabled? (yes/no) > ") console.log("Attempting to save your credentials...") loader = Loader("Saving Credentials...", "Done!").start() # you can also put a while loop here, e.g. while VideoIsBeingMade == True: ... @@ -94,6 +96,8 @@ with open('.env', 'a') as f: f.write(f'REDDIT_USERNAME="{user}"\n') time.sleep(0.5) f.write(f'REDDIT_PASSWORD="{passw}"\n') + time.sleep(0.5) + f.write(f'REDDIT_2FA="{twofactor}"\n') with open('.setup-done-before', 'a') as f: f.write("This file blocks the setup assistant from running again. Delete this file to run setup again.") From 6b8b96665cb411a0ba89d964e05c411ff8eed48b Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Thu, 2 Jun 2022 16:26:32 -0400 Subject: [PATCH 16/20] Accept Incoming Change --- reddit/subreddit.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index ce4e342..e4a6e69 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -28,14 +28,6 @@ def get_subreddit_threads(): passkey = os.getenv("REDDIT_PASSWORD") content = {} -<<<<<<< HEAD:reddit/askreddit.py - load_dotenv() - console.log("Logging in to reddit...") -||||||| 5b39896:reddit/askreddit.py - load_dotenv() -======= - ->>>>>>> 6fc5d2a7377dfe9f65d0d011fc260602527847c9:reddit/subreddit.py reddit = praw.Reddit( client_id=os.getenv("REDDIT_CLIENT_ID"), client_secret=os.getenv("REDDIT_CLIENT_SECRET"), @@ -77,14 +69,6 @@ def get_subreddit_threads(): except AttributeError as e: pass -<<<<<<< HEAD:reddit/askreddit.py - print_substep("Received AskReddit threads Successfully.", style="bold green") - return content -||||||| 5b39896:reddit/askreddit.py - print_substep("Received AskReddit threads Successfully.", style="bold green") - return content -======= print_substep("Received AskReddit threads successfully.", style="bold green") return content ->>>>>>> 6fc5d2a7377dfe9f65d0d011fc260602527847c9:reddit/subreddit.py From 20217be743aad2b7e2d30e608304eb1fc921c9da Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Fri, 3 Jun 2022 13:22:23 -0400 Subject: [PATCH 17/20] resolve gitignore conflict --- .gitignore | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.gitignore b/.gitignore index b85be09..6cf136b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,13 +2,7 @@ assets/ reddit/__pycache__/ utils/__pycache__/ .env -<<<<<<< HEAD reddit-bot-351418-5560ebc49cac.json video_creation/__pycache__/ .setup-done-before -||||||| 5b39896 -reddit-bot-351418-5560ebc49cac.json -======= -reddit-bot-351418-5560ebc49cac.json __pycache__ ->>>>>>> 6fc5d2a7377dfe9f65d0d011fc260602527847c9 From 49da171b55f562378d01f3bf2a8aa8decd45b2d8 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Sun, 5 Jun 2022 07:35:45 -0400 Subject: [PATCH 18/20] Add OPACITY, SUBREDDIT, and THEME. --- setup.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index f49b03b..feaa344 100644 --- a/setup.py +++ b/setup.py @@ -56,6 +56,9 @@ console.log("[bold green]Reddit Client Secret") console.log("[bold green]Reddit Username") console.log("[bold green]Reddit Password") console.log("[bold green]Reddit 2FA (yes or no)") +console.log("[bold green]Opacity (range of 0-1, decimals are OK)") +console.log("[bold green]Subreddit (without r/ or /r/)") +console.log("[bold green]Theme (light or dark)") time.sleep(0.5) console.print("[green]If you don't have these, please follow the instructions in the README.md file to set them up.") console.print("[green]If you do have these, type yes to continue. If you dont, go ahead and grab those quickly and come back.") @@ -80,6 +83,9 @@ cliSec = input("Client Secret > ") user = input("Username > ") passw = input("Password > ") twofactor = input("2fa Enabled? (yes/no) > ") +opacity = input("Opacity? (range of 0-1) > ") +subreddit = input("Subreddit (without r/) > ") +theme = input("Theme? (light or dark) > ") console.log("Attempting to save your credentials...") loader = Loader("Saving Credentials...", "Done!").start() # you can also put a while loop here, e.g. while VideoIsBeingMade == True: ... @@ -98,6 +104,12 @@ with open('.env', 'a') as f: f.write(f'REDDIT_PASSWORD="{passw}"\n') time.sleep(0.5) f.write(f'REDDIT_2FA="{twofactor}"\n') + time.sleep(0.5) + f.write(f'THEME="{theme}"\n') + time.sleep(0.5) + f.write(f'SUBREDDIT="{subreddit}"\n') + time.sleep(0.5) + f.write(f'OPACITY="{opacity}"\n') with open('.setup-done-before', 'a') as f: f.write("This file blocks the setup assistant from running again. Delete this file to run setup again.") @@ -107,4 +119,4 @@ loader.stop() console.log("[bold green]Setup Complete! Returning...") # Post-Setup: send message and try to run main.py again. -os.system("python3 main.py") \ No newline at end of file +os.system("python3 main.py") From c6ab604c186e892b962f026e69997753edf8d83a Mon Sep 17 00:00:00 2001 From: Lewis Menelaws Date: Sun, 5 Jun 2022 13:44:12 -0400 Subject: [PATCH 19/20] Fixed a couple of issues.. --- main.py | 84 +++++++++++++++++++++++++++------------------ reddit/subreddit.py | 25 ++++++++------ 2 files changed, 65 insertions(+), 44 deletions(-) diff --git a/main.py b/main.py index 689ca14..6ebb0ea 100644 --- a/main.py +++ b/main.py @@ -11,12 +11,19 @@ from video_creation.screenshot_downloader import download_screenshots_of_reddit_ 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"] +REQUIRED_VALUES = [ + "REDDIT_CLIENT_ID", + "REDDIT_CLIENT_SECRET", + "REDDIT_USERNAME", + "REDDIT_PASSWORD", + "OPACITY", +] 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_secret=os.getenv("REDDIT_CLIENT_SECRET") -username=os.getenv("REDDIT_USERNAME") -password=os.getenv("REDDIT_PASSWORD") -reddit2fa=os.getenv("REDDIT_2FA") +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"): shutil.copy(".env.template", ".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}\"") + 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") - else: - if 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() - - - exit() + 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") + else: + if 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() + + 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") + 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...") -load_dotenv() 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() chop_background_video(length) final_video = make_final_video(number_of_comments) - - 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_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) \ No newline at end of file + final_video = make_final_video(number_of_comments) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 9624e35..58ada57 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -1,8 +1,11 @@ -from rich import Console +from rich.console import Console from utils.console import print_markdown, print_step, print_substep from dotenv import load_dotenv + console = Console() import os, random, praw, re + + def get_subreddit_threads(): global submission """ @@ -39,7 +42,9 @@ def get_subreddit_threads(): # ! Prompt the user to enter a subreddit try: 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: subreddit = reddit.subreddit("askreddit") @@ -56,14 +61,14 @@ def get_subreddit_threads(): content["comments"] = [] for top_level_comment in submission.comments: - if not top_level_comment.stickied: - content["comments"].append( - { - "comment_body": top_level_comment.body, - "comment_url": top_level_comment.permalink, - "comment_id": top_level_comment.id, - } - ) + if not top_level_comment.stickied: + content["comments"].append( + { + "comment_body": top_level_comment.body, + "comment_url": top_level_comment.permalink, + "comment_id": top_level_comment.id, + } + ) except AttributeError as e: pass From 3693dce2cad58315b0a1462ee182207880cecfbc Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Sun, 5 Jun 2022 16:37:17 -0400 Subject: [PATCH 20/20] Update main.py --- main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/main.py b/main.py index 6ebb0ea..61ccbbb 100644 --- a/main.py +++ b/main.py @@ -50,7 +50,6 @@ time.sleep(1) if not os.path.exists(".env"): - shutil.copy(".env.template", ".env") configured = False console.log("[red] Your .env file is invalid, or was never created. Standby.")