updated selecting account and delete account
This commit is contained in:
@@ -256,32 +256,18 @@ def ask_for_account_details():
|
|||||||
|
|
||||||
def select_account(accounts, wording = "edit"):
|
def select_account(accounts, wording = "edit"):
|
||||||
print("Which account would you like to {}:".format(wording))
|
print("Which account would you like to {}:".format(wording))
|
||||||
|
emails = list(accounts)
|
||||||
for i in range(0, len(accounts)):
|
for i in range(0, len(accounts)):
|
||||||
pretty_number = i + 1
|
pretty_number = i + 1
|
||||||
print("{}) {}".format(pretty_number, accounts[i]))
|
print("{}) {}".format(pretty_number, emails[i]))
|
||||||
while True:
|
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:
|
try:
|
||||||
return accounts[account_to_edit]
|
return emails[account_to_modify]
|
||||||
except IndexError as error:
|
except IndexError as error:
|
||||||
print("you entered a number out of range, please try again")
|
print("you entered a number out of range, please try again")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
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
|
# Build and parse arguments
|
||||||
parser = optparse.OptionParser(
|
parser = optparse.OptionParser(
|
||||||
@@ -390,16 +376,13 @@ if __name__ == "__main__":
|
|||||||
break
|
break
|
||||||
|
|
||||||
elif user_input.casefold() == "d":
|
elif user_input.casefold() == "d":
|
||||||
config = configparser.ConfigParser()
|
account_to_delete = select_account(accounts, "delete")
|
||||||
config.read(secrets_config_file)
|
print("Are you sure you wish to delete {} account? ".format(account_to_delete))
|
||||||
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> ")
|
confirmation = input("y/n> ")
|
||||||
if not confirmation.casefold() in ["y","yes"]:
|
if not confirmation.casefold() in ["y","yes"]:
|
||||||
break
|
break
|
||||||
config.remove_section(account_section_to_delete)
|
del accounts[account_to_delete]
|
||||||
with open(secrets_config_file, "w") as configfile:
|
write_config_file(accounts, secrets_config_file)
|
||||||
config.write(configfile)
|
|
||||||
break
|
break
|
||||||
|
|
||||||
elif user_input.casefold() == "q":
|
elif user_input.casefold() == "q":
|
||||||
|
|||||||
Reference in New Issue
Block a user