From: Samir Benmendil Date: Tue, 31 Jan 2023 23:33:09 +0000 (+0000) Subject: bin: update monzo and starling qif filters X-Git-Url: https://git.rmz.io/dotfiles.git/commitdiff_plain/1fc109f72ba730d8edb654cd84397cfd612c635d?ds=sidebyside bin: update monzo and starling qif filters * monzo to support both current and joint account * actual account_ids left out for privacy reasons * starling to discard declined entries --- diff --git a/bin/monzo.py b/bin/monzo.py index e54aae5..722cc5f 100755 --- a/bin/monzo.py +++ b/bin/monzo.py @@ -7,15 +7,29 @@ import sys outformat = "qif" # outformat = "csv" +class UnknownAccountError(Exception): + pass + +def get_account(data): + account_id = data["transactions"][0]["account_id"] + if account_id == "": + return "Accounts:Monzo" + elif account_id == "": + return "Accounts:Joint Account" + + raise UnknownAccountError(account_id) + if __name__ == "__main__": - if outformat == "qif": - print("!Account") - print("NCurrent Accounts:Monzo") - print("^") - 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) + + if outformat == "qif": + print("!Account") + print("NCurrent {}".format(get_account(data))) + print("^") + print("!Type:Bank") + + cnt = 1 for t in data.get("transactions"): if t.get("decline_reason", ""): continue diff --git a/bin/starling.py b/bin/starling.py index 0941cbb..471cd14 100755 --- a/bin/starling.py +++ b/bin/starling.py @@ -12,6 +12,8 @@ class FeedError(Exception): def read_feed_item(i): try: + if i.get("status", "") == "DECLINED": + return date = datetime.strptime(i["transactionTime"], "%Y-%m-%dT%H:%M:%S.%fZ") amount = i["amount"]["minorUnits"] / 100 if i["direction"] == "OUT":