forked from zabatakram/Py_Expense_template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpense.py
More file actions
55 lines (49 loc) · 1.3 KB
/
expense.py
File metadata and controls
55 lines (49 loc) · 1.3 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
from PyInquirer import prompt
import csv
from prompt_toolkit.validation import Validator, ValidationError
from user import get_user, get_user_option
class NumberValidator(Validator):
def validate(self, document):
try:
int(document.text)
except ValueError:
raise ValidationError(
message='Please enter a number',
cursor_position=len(document.text))
expense_questions = [
{
"type":"input",
"name":"amount",
"message":"New Expense - Amount: ",
"validate": NumberValidator,
},
{
"type":"input",
"name":"label",
"message":"New Expense - Label: ",
},
{
"type":"list",
"name":"user",
"message":"New Expense - Spender: ",
"choices": get_user
},
{
'type': 'checkbox',
'qmark': '➡',
'message': 'Select all the spenders',
'name': 'allspenders',
"choices": get_user_option,
},
]
def new_expense(*args):
infos = prompt(expense_questions)
with open('expense_report.csv', 'a') as f:
# create the csv writer
writer = csv.writer(f)
# write a row to the csv file
writer.writerow(infos.values())
print("Expense Added !")
return True
def show_status():
return True