From 16664e010a8d57a89acef3ad576143e8580c8330 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Thu, 2 Jun 2022 13:11:10 -0400 Subject: [PATCH] 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...")