This repository was archived by the owner on Nov 28, 2023. It is now read-only.
forked from TktMaxime/Py_Expense_template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatus.py
63 lines (53 loc) · 1.77 KB
/
status.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
from PyInquirer import prompt
from utils import append_list_as_row
import json
import csv
from utils import append_list_as_row
def show_status():
debt = {}
for user in list(csv.reader(open("users.csv"))):
debt[user[0]] = {}
# calculate report
data = list(csv.reader(open("expense_report.csv")))
for i, row in enumerate(data):
spender = row[2]
count = (len(row) - 2)
amount = float(row[0]) / count
for j, el in enumerate(row[3:]):
otherSpender = el
if spender not in debt[otherSpender].keys():
debt[otherSpender][spender] = 0
debt[otherSpender][spender] += amount
# not working for now
# # optimize
# for key, row in debt.items():
# spender = row[2]
# for key3, val3 in row.items():
# # search spender occurences in other other
# for key2, row2 in debt.items():
# if key2 != key and key2 == key3:
# if key in row2.keys():
# print(val3, row2[key])
# print report
for key, row in debt.items():
print(f"{key} owes", end="")
if len(row.keys()) == 0:
print(" nothing", end="")
else:
for key, val in row.items():
print(f" {val}€ to {key}", end="")
print("")
# print report
report = []
for key, row in debt.items():
if len(row.keys()) != 0:
for key2, val in row.items():
report.append(f"{key} owes {val}€ to {key2}")
filteredReport = [{"name": x} for x in report]
infos = prompt({
"type": "checkbox",
"name": "other",
"message": "Mark Debt payed",
"choices": filteredReport,
})
return True