-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathexpense.py
executable file
·66 lines (64 loc) · 1.73 KB
/
expense.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
from PyInquirer import prompt
from csv import writer
from user import getUsersList
expense_questions = [
{
"type": "input",
"name": "amount",
"message": "New Expense - Amount: ",
},
{
"type": "input",
"name": "label",
"message": "New Expense - Label: ",
},
{
"type": "list",
"name": "spender",
"message": "New Expense - Spender: ",
"choices": getUsersList()
},
{
"type": "checkbox",
"name": "involved",
"message": "New Expense - Involved People : ",
"choices": getUsersList(),
}
]
def new_expense(*args):
infos = prompt(expense_questions)
expenseFileName = open("expense_report.csv", "a+")
expenseFile = writer(expenseFileName)
# Test if spender is user
amount = 0
spender = infos["spender"]
# Test Valid Amount
try:
amount = float(infos["amount"])
except:
print("Invalid Amount")
expenseFileName.close()
return False
# Check Involved People
involved = infos["involved"]
# No Body is involved
if (not involved):
print("Invalid Involved people selection")
expenseFileName.close()
return False
# Spender not involved
if not spender in involved:
ask = "Is this expense also for you ? [y/n]"
if (ask.lower() == "y"):
involved.append(spender)
involvedString = ""
for i in involved:
if not involvedString:
involvedString = i
else:
involvedString = involvedString + ' ' + i
expenseFile.writerow([amount, infos["label"], spender, involvedString])
# Closing files
expenseFileName.close()
print("Expense Added !")
return True