]>
git.rmz.io Git - dotfiles.git/blob - bin/monzo.py
3 from datetime
import datetime
11 class UnknownAccountError(Exception):
15 def get_account(data
):
16 account_id
= data
["transactions"][0]["account_id"]
18 return "Accounts:Monzo"
19 elif account_id
== "":
20 return "Accounts:Joint Account"
22 raise UnknownAccountError(account_id
)
25 if __name__
== "__main__":
26 with open(sys
.argv
[1], 'r') if len(sys
.argv
) > 1 else sys
.stdin
as fp
:
29 if outformat
== "qif":
31 print("NCurrent {}".format(get_account(data
)))
36 for t
in data
.get("transactions"):
37 if t
.get("decline_reason", ""):
41 date
= datetime
.strptime(t
["created"], "%Y-%m-%dT%H:%M:%S.%fZ")
43 date
= datetime
.strptime(t
["created"], "%Y-%m-%dT%H:%M:%SZ")
44 amount
= t
["amount"] / 100
45 if "name" in t
.get("counterparty", {}):
46 payee
= t
["counterparty"]["name"]
47 elif t
["merchant"] is None:
48 payee
= t
["description"]
50 payee
= t
["merchant"]["name"]
51 memo
= t
["description"]
53 memo
= "Tab: {}".format(t
["tab"]["name"])
57 memo
+= "\n{local_amount} {local_currency}".format(**t
)
59 if outformat
== "csv":
60 print('{date:%Y-%m-%d},{amount},"{payee}","{description}","{notes}"'.format(date
=date
,
64 elif outformat
== "qif":
65 print("D{:%Y-%m-%d}".format(date
))
66 print("T{}".format(amount
))
67 print("P{}".format(payee
))
68 print("M{}".format(memo
))
69 print("#{}".format(t
['id']))