--- /dev/null
+#!/usr/bin/env python3
+
+from datetime import datetime
+import json
+import sys
+
+outformat = "qif"
+# outformat = "csv"
+
+if __name__ == "__main__":
+ if outformat == "qif":
+ print("!Type:Bank")
+ cnt = 1
+ with open(sys.argv[1], 'r') if len(sys.argv) > 1 else sys.stdin as fp:
+ data = json.load(fp)
+ for t in data.get("transactions"):
+ try:
+ date = datetime.strptime(t["created"], "%Y-%m-%dT%H:%M:%S.%fZ")
+ except ValueError:
+ date = datetime.strptime(t["created"], "%Y-%m-%dT%H:%M:%SZ")
+ amount = t["amount"] / 100
+ if "name" in t.get("counterparty", {}):
+ payee = t["counterparty"]["name"]
+ elif t["merchant"] is None:
+ payee = t["description"]
+ else:
+ payee = t["merchant"]["name"]
+ memo = t["description"]
+ memo += "\n{local_amount} {local_currency}".format(**t)
+ notes = t["notes"]
+ if outformat == "csv":
+ print('{date:%Y-%m-%d},{amount},"{payee}","{description}","{notes}"'.format(date=date,
+ payee=payee,
+ amount=amount,
+ **t))
+ elif outformat == "qif":
+ print("D{:%Y-%m-%d}".format(date))
+ print("T{}".format(amount))
+ print("P{}".format(payee))
+ print("M{}".format(memo))
+ print("#{}".format(t['id']))
+ print("^")
+ cnt += 1
--- /dev/null
+#!/usr/bin/env python3
+
+from datetime import datetime
+import json
+import sys
+
+outformat = "qif"
+# outformat = "csv"
+
+class FeedError(Exception):
+ pass
+
+def read_feed_item(i):
+ try:
+ date = datetime.strptime(i["transactionTime"], "%Y-%m-%dT%H:%M:%S.%fZ")
+ amount = i["amount"]["minorUnits"] / 100
+ if i["direction"] == "OUT":
+ amount = -amount
+ payee = i["counterPartyName"]
+ reference = i.get("reference", payee)
+ if outformat == "csv":
+ print('{date:%Y-%m-%d},{amount},"{payee}","{description}","{notes}"'.format(date=date,
+ payee=payee,
+ amount=amount,
+ description=reference,
+ notes=reference))
+ elif outformat == "qif":
+ print("D{:%Y-%m-%d}".format(date))
+ print("T{}".format(amount))
+ print("P{}".format(payee))
+ print("M{}".format(reference))
+ print("#{}".format(i['feedItemUid']))
+ print("^")
+ except KeyError:
+ raise FeedError(i['feedItemUid'])
+
+
+if __name__ == "__main__":
+ if outformat == "qif":
+ print("!Type:Bank")
+ cnt = 1
+ with open(sys.argv[1], 'r') if len(sys.argv) > 1 else sys.stdin as fp:
+ data = json.load(fp)
+ for i in data.get('feedItems'):
+ read_feed_item(i)
+ cnt += 1