-
Notifications
You must be signed in to change notification settings - Fork 50
/
status.py
49 lines (43 loc) · 1.45 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
from csv import reader
def handle_line(line, debts):
spender = line[2]
amount = float(line[0])
involved = line[3].split(" ")
toPay = amount / len(involved)
for user in involved:
if (user == spender):
continue
debts.append([user, spender, toPay])
def printDebt(debt):
print(debt[0] + " owes " + str(debt[2]) + " to " + debt[1])
def get_status(*args):
with open("expense_report.csv", 'r') as csv:
expenses = reader(csv)
debts = []
# Parcours des dettes
for expense in expenses:
handle_line(expense, debts)
finalDebts = []
for i in debts:
isPresent = False
for j in finalDebts:
if i[0] == j[0] and i[1] == j[1]:
isPresent = True
j[2] = i[2] + j[2]
# if i[0] == j[1] and i[1] == j[0]:
# isPresent = True
# if (j[2] - i[2] > 0):
# j[2] = j[2] - i[2]
# elif (j[2] - i[2] == 0):
# finalDebts.remove(j)
# else:
# toPay = i[2] - j[2]
# j[0] = i[0]
# j[1] = i[1]
# j[2] = toPay
if not isPresent:
finalDebts.append(i)
# Affichage des dettes
for debt in finalDebts:
printDebt(debt)
return True