-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathmain.py
119 lines (100 loc) · 3.93 KB
/
main.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import sys
import os
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), 'app')))
from app.database import Database
from app.transaction import Transaction
from app.report import generate_report
from app.config import save_currency_symbol, load_currency_symbol
from app.budget import Budget
from app.alert import Alerts
from export import export_report_to_csv
from sns.aws_sns import SNSNotifier
def main_menu():
print("\nPersonal Finance Tracker")
print("1. Add Transaction")
print("2. View Transactions")
print("3. Generate Report")
print("4. Manage Budget")
print("5. Clear All Transactions")
print("6. Export Report to CSV") # New option
print("7. Exit")
return input("Choose an option: ")
def add_transaction(db, currency_symbol, alerts):
amount = float(input("Enter amount: "))
category = input("Enter category: ")
description = input("Enter description: ")
transaction_type = input("Enter type (income/expense): ").lower()
# Create a Transaction object
transaction = Transaction(amount, category, description, transaction_type)
# Add the transaction to the database
db.add_transaction(transaction)
print(f"Transaction added successfully! {currency_symbol}{amount:.2f}")
# Check alerts after adding the transaction
transactions = db.get_all_transactions()
alerts.check_alerts(transactions)
def view_transactions(db, currency_symbol):
transactions = db.get_all_transactions()
for txn in transactions:
print(f"{txn.date}: {txn.type.capitalize()} - {currency_symbol}{txn.amount:.2f} - {txn.category} - {txn.description}")
def manage_budget(budget, currency_symbol):
while True:
print("\nBudget Management")
print("1. Set Budget")
print("2. View Budgets")
print("3. Back to Main Menu")
choice = input("Choose an option: ")
if choice == '1':
category = input("Enter category: ")
amount = float(input("Enter budget amount: "))
budget.set_budget(category, amount)
elif choice == '2':
budget.view_budgets()
elif choice == '3':
break
else:
print("Invalid choice. Please try again.")
def main():
# Ask user to set currency symbol
currency_symbol = input("Enter your preferred currency symbol: ")
save_currency_symbol(currency_symbol)
# Load currency symbol
CURRENCY_SYMBOL = load_currency_symbol()
db = Database()
budget = Budget(CURRENCY_SYMBOL)
alerts = Alerts(budget)
use_sns = input("Do you want to enable AWS SNS alerts? (yes/no): ").strip().lower() == 'yes'
sns_notifier = SNSNotifier() if use_sns else None
# Ask for the user's email
email = input("Enter your email address to receive notifications: ")
if use_sns:
# Request user's email for SNS notifications
email = input("Enter your email address to receive notifications: ")
sns_notifier = SNSNotifier()
sns_notifier.setup(email)
else:
sns_notifier = None
while True:
choice = main_menu()
if choice == '1':
add_transaction(db, CURRENCY_SYMBOL,alerts)
elif choice == '2':
view_transactions(db, CURRENCY_SYMBOL)
elif choice == '3':
generate_report(db, CURRENCY_SYMBOL)
elif choice == '4':
manage_budget(budget, CURRENCY_SYMBOL)
elif choice == '5':
# Clear all transactions
db.clear_transactions()
elif choice == '6':
export_report_to_csv(db, CURRENCY_SYMBOL)
elif choice == '7':
# Check alerts before exiting
transactions = db.get_all_transactions()
alerts.check_alerts(transactions)
print("Thank you for using Personal Finance Tracker!")
sys.exit(0)
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main()