-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_menu.py
72 lines (68 loc) · 2.18 KB
/
main_menu.py
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
# main_menu.py
# Script to execute Finance Program in Command Line.
import trans_entry
import trans_view
import trans_edit
import account_init
import account_edit
import account_view
import account_analysis
import initialize
import save
import basecui as bc
import os
# Initialiation of variables
data_file_str="data.txt"
menu = """
MAIN MENU
========================================
[ntr] : Enter Transactions
[edt] : Edit Transactions
[vts] : View Transactions
[eda] : Edit Accounts
[vwa] : View Accounts
[ana] : Analyze Accounts
[esc] : Exit menu
"""
# Script
# Ensure file exists
if not os.path.isfile(data_file_str):
data_file = open(data_file_str, "w")
data_file.close()
variables, accounts, transactions_dirty=initialize.main(data_file_str)
transactions = bc.remove_duplicates(transactions_dirty) # Remove impure Transactions (duplicates)
# Menu looping
while True:
print(menu)
try:
choice = input("Your choice: ").rstrip()
if choice == "ntr":
transactions += trans_entry.main()
# Add data to Account objects
accounts_t=(account_init.create_from(transactions))
# Account for duplicate Accounts created from Transactions
accounts=account_init.merge_accounts(accounts_t + accounts)
elif choice == "edt":
trans_edit.main(transactions, accounts)
# Many Accounts may be updated
for a in accounts:
a.update_all_reached()
elif choice == "vts":
trans_view.main(transactions)
elif choice == "eda":
account_edit.main(accounts)
elif choice == "vwa":
account_view.main(accounts)
elif choice == "ana":
account_analysis.main(accounts)
elif choice == "esc":
break
else:
raise ValueError("Choice {} unacceptable. Try again.".format(choice))
except ValueError as e:
print(" An error has occurred: {}".format(e))
except Exception as e:
raise
print(" Fatal Error: {}".format(e))
finally:
save.main(transactions, accounts, variables, data_file_str)