updated selecting account and delete account

This commit is contained in:
crp3844
2022-09-07 13:44:56 -04:00
parent acbcfa1c1d
commit 248aa408ba

View File

@@ -256,32 +256,18 @@ def ask_for_account_details():
def select_account(accounts, wording = "edit"):
print("Which account would you like to {}:".format(wording))
emails = list(accounts)
for i in range(0, len(accounts)):
pretty_number = i + 1
print("{}) {}".format(pretty_number, accounts[i]))
print("{}) {}".format(pretty_number, emails[i]))
while True:
account_to_edit = int(input("Please enter number relating to the account you wish to {}: ".format(wording))) - 1
account_to_modify = int(input("Please enter number relating to the account you wish to {}: ".format(wording))) - 1
try:
return accounts[account_to_edit]
return emails[account_to_modify]
except IndexError as error:
print("you entered a number out of range, please try again")
if __name__ == "__main__":
# INI config does not exist
#if not does_file_exist(secrets_config_file):
# account_details = ask_for_account_details()
# config = configparser.ConfigParser()
# config[account_details["account_email_address"]] = {}
# config[account_details["account_email_address"]]["account_api_client_id"] = account_details["account_api_client_id"]
# config[account_details["account_email_address"]]["account_api_secret"] = account_details["account_api_secret"]
# config[account_details["account_email_address"]]["account_vault_password"] = account_details["account_vault_password"]
# with open(secrets_config_file, "w") as configfile:
# config.write(configfile)
#config = configparser.ConfigParser()
#config.read(secrets_config_file)
#accounts = config.sections()
# decrypt all values for easy update a
# Build and parse arguments
parser = optparse.OptionParser(
@@ -390,16 +376,13 @@ if __name__ == "__main__":
break
elif user_input.casefold() == "d":
config = configparser.ConfigParser()
config.read(secrets_config_file)
account_section_to_delete = select_account(accounts, "delete")
print("Are you sure you wish to delete {} account? ".format(account_section_to_delete))
account_to_delete = select_account(accounts, "delete")
print("Are you sure you wish to delete {} account? ".format(account_to_delete))
confirmation = input("y/n> ")
if not confirmation.casefold() in ["y","yes"]:
break
config.remove_section(account_section_to_delete)
with open(secrets_config_file, "w") as configfile:
config.write(configfile)
del accounts[account_to_delete]
write_config_file(accounts, secrets_config_file)
break
elif user_input.casefold() == "q":