From 5958bfdd55637296b0cccb48b8a64d9e0b81a0b4 Mon Sep 17 00:00:00 2001 From: John Gaunt Date: Tue, 6 Sep 2022 20:39:56 -0400 Subject: [PATCH] added while loop for top level config menu, updated delete question to standard we are using --- bitwardenBackup.py | 74 ++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/bitwardenBackup.py b/bitwardenBackup.py index 0f73f35..736f21b 100644 --- a/bitwardenBackup.py +++ b/bitwardenBackup.py @@ -113,44 +113,46 @@ if __name__ == "__main__": sys.exit(0) else: print("This value must be one of the following characters: n, q.") - - config = configparser.ConfigParser() - config.read(secrets_ini_file) - accounts = config.sections() - print("Current Bitwarden accounts:") - for account in accounts: - print(account) - print(" ") - print("e) Edit account") - print("n) New account") - print("d) Delete account") - print("q) Quit config") while True: - user_input = input("e/n/d/q> ") - if user_input.casefold() == "e": - print("") - elif user_input.casefold() == "n": - account_details = ask_for_account_details() - config.add_section(account_details["account_email_address"]) - for key in account_details.keys(): - if not key == "account_email_address": - config.set(account_details["account_email_address"], key, account_details[key]) - with open(secrets_ini_file, "w") as configfile: - config.write(configfile) - break - elif user_input.casefold() == "d": - account_section_to_delete = select_account(accounts, "delete") - confirmation = input("Are you sure you wish to delete {} account?".format(account_section_to_delete)) - if not confirmation.casefold() in ["y","yes"]: + config = configparser.ConfigParser() + config.read(secrets_ini_file) + accounts = config.sections() + print("Current Bitwarden accounts:") + print(" ") + for account in accounts: + print(account) + print(" ") + print("e) Edit account") + print("n) New account") + print("d) Delete account") + print("q) Quit config") + while True: + user_input = input("e/n/d/q> ") + if user_input.casefold() == "e": + account_section_to_edit = select_account(accounts) + elif user_input.casefold() == "n": + account_details = ask_for_account_details() + config.add_section(account_details["account_email_address"]) + for key in account_details.keys(): + if not key == "account_email_address": + config.set(account_details["account_email_address"], key, account_details[key]) + with open(secrets_ini_file, "w") as configfile: + config.write(configfile) break - config.remove_section(account_section_to_delete) - with open(secrets_ini_file, "w") as configfile: - config.write(configfile) - break - elif user_input.casefold() == "q": - sys.exit(0) - else: - print("This value must be one of the following characters: e, n, d, q.") + elif user_input.casefold() == "d": + account_section_to_delete = select_account(accounts, "delete") + print("Are you sure you wish to delete {} account? ".format(account_section_to_delete)) + confirmation = input("y/n> ") + if not confirmation.casefold() in ["y","yes"]: + break + config.remove_section(account_section_to_delete) + with open(secrets_ini_file, "w") as configfile: + config.write(configfile) + break + elif user_input.casefold() == "q": + sys.exit(0) + else: + print("This value must be one of the following characters: e, n, d, q.") sys.exit(0)