From 5a85948cfe923e14f70faa3f74aae55818cfbb5a Mon Sep 17 00:00:00 2001 From: micziz Date: Sun, 12 Jun 2022 15:11:35 +0200 Subject: [PATCH] Implement a save system and allow rerunning setup --- .env.template | 20 -------------------- .gitignore | 1 + setup.py | 25 +++++++++++++++++-------- 3 files changed, 18 insertions(+), 28 deletions(-) delete mode 100644 .env.template diff --git a/.env.template b/.env.template deleted file mode 100644 index e95c209..0000000 --- a/.env.template +++ /dev/null @@ -1,20 +0,0 @@ -REDDIT_CLIENT_ID="" -REDDIT_CLIENT_SECRET="" - -REDDIT_USERNAME="" -REDDIT_PASSWORD="" - -# Valid options are "yes" and "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" - -# Valid options are "light" and "dark" -THEME="" - -# Enter a subreddit, e.g. "AskReddit" -SUBREDDIT="" - -# Range is 0 -> 1 -OPACITY="0.9" diff --git a/.gitignore b/.gitignore index 72e6fc7..4f286c8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ assets/ reddit/__pycache__/ utils/__pycache__/ .env +.env-save reddit-bot-351418-5560ebc49cac.json video_creation/__pycache__/ .setup-done-before diff --git a/setup.py b/setup.py index feaa344..690554f 100644 --- a/setup.py +++ b/setup.py @@ -15,11 +15,15 @@ from utils.loader import Loader from os.path import exists console = Console() -setup_done = exists(".setup-done-before") +setup_done = exists(".setup-block.txt") 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() + console.log("[red]Setup was already completed! Do you want to run the script again?") + run_again = input("> ") + if run_again == "y": + os.remove(".setup-block.txt") + else: + exit() # These lines ensure the user: # - knows they are in setup mode @@ -71,6 +75,12 @@ else: console.print("[bold green]Alright! Let's get started!") time.sleep(1) + +console.log("[green]Saving your old .env in .env-save credentials...") +with open(".env", "r") as f: + with open(".env-save", "w") as f2: + f2.write(f.read()) + """ Begin the setup process. @@ -88,13 +98,12 @@ 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: ... +# 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: +with open('.env', 'w') as f: f.write(f'REDDIT_CLIENT_ID="{cliID}"\n') time.sleep(0.5) f.write(f'REDDIT_CLIENT_SECRET="{cliSec}"\n') @@ -111,8 +120,8 @@ with open('.env', 'a') as f: 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.") +with open('.setup-block.txt', 'a') as f: + f.write("This file blocks the setup assistant from running again unless you re-run the script.") loader.stop()