forked from TktMaxime/Py_Expense_template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpense.py
More file actions
82 lines (57 loc) · 1.82 KB
/
expense.py
File metadata and controls
82 lines (57 loc) · 1.82 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
from PyInquirer import prompt
import csv
import json
def get_participants_list(answers):
f = open("users.csv","r")
myReader = csv.reader(f)
participants = []
for row in myReader:
participants.append(str(row).replace("[","").replace("]","").replace("\'",""))
return participants
def get_spender_list(answers):
f = open("users.csv","r")
myReader = csv.reader(f)
spender = []
for row in myReader:
spender.append({'name': str(row)})
return spender
expense_questions = [
{
"type":"input",
"name":"amount",
"message":"New Expense - Amount: ",
},
{
"type":"input",
"name":"label",
"message":"New Expense - Label: ",
},
{
"type":"list",
"name":"spender",
"message":"Expense Tracker v0.1",
"choices":get_participants_list,
},
{
"type":"checkbox",
"name":"participants",
"message":"Expense Tracker v0.1",
"choices": get_spender_list,
},
]
def new_expense(*args):
infos = prompt(expense_questions)
f = open("expense_report.csv", "a")
participants = ""
for participant in infos["participants"]:
print(participant)
participants += str(participant).replace("[","").replace("]","").replace("\'","")
participants += "-"
str_participants = str(participants)
if not infos["spender"] in str_participants:
str_participants += infos["spender"] + "-"
f.write(str(infos["amount"]) + "," + str(infos["label"]) + "," + str(infos["spender"]) + "," + str_participants[:len(str_participants)-1] + "\n")
f.close
# Writing the informations on external file might be a good idea ¯\_(ツ)_/¯
print("Expense Added !")
return True