X-Git-Url: https://git.rmz.io/dotfiles.git/blobdiff_plain/80fa553cc77084a9e31f7c1ce3154afb817c1262..7dd48bb77afddcd296bc0a77d01cf159e247ef3b:/bin/monzo.py?ds=sidebyside 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