]>
git.rmz.io Git - dotfiles.git/blob - bin/starling.py
7f4615071c77e142d72a8638584d6651b8b393b0
3 from datetime
import datetime
10 class FeedError(Exception):
13 def read_feed_item(i
):
15 if i
.get("status", "") == "DECLINED":
17 date
= datetime
.strptime(i
["transactionTime"], "%Y-%m-%dT%H:%M:%S.%f%z")
18 amount
= i
["amount"]["minorUnits"] / 100
19 if i
["direction"] == "OUT":
21 payee
= i
["counterPartyName"]
22 reference
= i
.get("reference", payee
)
23 if outformat
== "csv":
24 print('{date:%Y-%m-%d},{amount},"{payee}","{description}","{notes}"'.format(date
=date
,
27 description
=reference
,
29 elif outformat
== "qif":
30 print("D{:%Y-%m-%d}".format(date
.astimezone(None)))
31 print("T{}".format(amount
))
32 print("P{}".format(payee
))
33 print("M{}".format(reference
))
34 print("#{}".format(i
['feedItemUid']))
37 raise FeedError(i
['feedItemUid'])
40 if __name__
== "__main__":
41 if outformat
== "qif":
43 print("NCurrent Accounts:Starling")
47 with open(sys
.argv
[1], 'r') if len(sys
.argv
) > 1 else sys
.stdin
as fp
:
49 for i
in data
.get('feedItems'):