-
Notifications
You must be signed in to change notification settings - Fork 0
/
payoff.py
executable file
·79 lines (66 loc) · 2.24 KB
/
payoff.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
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/python3
import argparse
import logging
import datetime
from dateutil import relativedelta
from dataclasses import dataclass, field
@dataclass
class PayoffCalculator:
total: float
date: datetime.date
payments: int
source: str
destination: str
payee: str
def calculate(self):
indention = " "
remaining = int(self.total * 100)
payment = int(remaining / self.payments)
log.info(
f"generating {self.total} payoff {self.source} -> {self.destination} for '{self.payee}'"
)
payment_date = self.date
for n in range(self.payments):
p = remaining if n == self.payments - 1 else payment
print(f"{payment_date.strftime('%Y/%m/%d')} * {self.payee}")
print(f"{indention}{self.source:50}-${p/100:.2f}")
print(f"{indention}{self.destination:50} ${p/100:.2f}")
print()
remaining -= p
payment_date += relativedelta.relativedelta(months=1)
if __name__ == "__main__":
logging.basicConfig(
level=logging.INFO,
format="[%(levelname)5s] %(message)s",
handlers=[
logging.StreamHandler(),
],
)
log = logging.getLogger("payoff")
parser = argparse.ArgumentParser(description="payoff tool")
parser.add_argument("-D", "--debug", action="store_true", default=False)
parser.add_argument("-p", "--payee", action="store", default="some random expense")
parser.add_argument(
"-s", "--source", action="store", default="[allocations:checking:auto:payoff]"
)
parser.add_argument(
"-d",
"--destination",
action="store",
default="[allocations:checking:savings:main:payoff]",
)
parser.add_argument("-t", "--total", action="store", default=1000, type=float)
parser.add_argument("-n", "--payments", action="store", default=12, type=int)
args = parser.parse_args()
if args.debug:
log.setLevel(logging.DEBUG)
date = datetime.date.today()
calculator = PayoffCalculator(
total=args.total,
payments=args.payments,
date=date,
source=args.source,
destination=args.destination,
payee=args.payee,
)
calculator.calculate()