-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.py
More file actions
92 lines (90 loc) · 4.02 KB
/
Main.py
File metadata and controls
92 lines (90 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import Config.JsonFiles as JsonFiles
import UI.KeyManagement as KeyManagement
import UI.AccountManagement as AccountManagement
import Models.AccountList as AccountList
import Config.TimeLapsed as TimeLapsed
import time
import os
def initialSetup():
accountList = AccountList.AccountList("", [])
JsonFiles.initialSetUp()
# check if accounts exists using accountsFileExists() from JsonFiles.py, if it does load it into a list of accounts using readAccountsFromFile() from JsonFiles.py
if JsonFiles.accountsFileExists() == True:
accountList = JsonFiles.readAccountsFromFile()
KeyManagement.CheckKey(accountList.key)
KeyManagement.checkIfFilesExist()
KeyManagement.createName()
AccountManagement.newAccount(accountList)
displayMenu(accountList)
#create an ascii menu with the title of "Dashboard", and options which can be executed by pressing a key: N = new account, M = modify account, Q = quit
def displayMenu(accountList):
# pause the program for a second, and then clear the console
time.sleep(2)
print("\033c")
print("Dashboard")
# show up to 15 accounts in accounts, if any, and give an option if there is more to the maximum
if len(accountList.accounts) > 0:
print("Accounts:")
for i in range(0, len(accountList.accounts)):
if i < 15:
print("(" + str(accountList.accounts[i].id) + ")\t" + accountList.accounts[i].websiteName)
print("\t\t" + accountList.accounts[i].username + "\tLastChecked: " + accountList.accounts[i].lastChecked.strftime("%m/%d/%Y"))
else:
print("...")
break
print("N = New Account")
print("M = Modify Account")
print("E = Export encripted data ")
print("D = Delete all files")
print("Q = Quit")
# get user input
userInput = input("Please enter a command: ")
# if the user input is N, execute newAccount()
if userInput.upper() == "N":
TimeLapsed.checkIfActive()
AccountManagement.createAccount(accountList)
# if the user input is M, execute modifyAccount()
elif userInput.upper() == "M":
TimeLapsed.checkIfActive()
# make a try catch block to check if the imput is a number, if it's not, display an error message and execute displayMenu()
try:
# promt the user to enter the id of the account they want to modify, save the inputs as "i" and substract 1 from it
i = int(input("Please enter the ID of the account you want to modify: ")) - 1
# execute printAccount() from AccountView.py
import UI.AccountView as AccountView
AccountView.printAccount(accountList.accounts[i], accountList)
except ValueError:
print("Error: Invalid input.")
displayMenu(accountList)
except IndexError:
print("Error: Invalid input.")
displayMenu(accountList)
displayMenu(accountList)
elif userInput.upper() == 'E':
TimeLapsed.checkIfActive()
# excecute exportAccount
import UI.AccountManagement as AM
AM.exportAccount(accountList)
# if the user input is Q, execute quit()
elif userInput.upper() == "Q":
quit()
# if the user input is D, execute deleteAllFiles() from JsonFiles.py and ask if the user is sure
elif userInput.upper() == "D":
print("Are you sure you want to delete all files?")
print("Y = Yes")
print("N = No")
userInput = input("Please enter a command: ")
if userInput.upper() == "Y":
JsonFiles.deleteAllFiles()
print("All files have been deleted, the program will close now.")
time.sleep(5)
quit()
elif userInput.upper() == "N":
displayMenu(accountList)
else:
print("Error: Invalid input.")
displayMenu(accountList)
# if the user input is not N, M, or Q, display an error message and execute displayMenu()
else:
print("Error: Invalid input.")
displayMenu(accountList)