X-Git-Url: https://git.rmz.io/dotfiles.git/blobdiff_plain/d15e050a98639d3be72af6f3e7523a80ffad0245..fdd63454b51a35418ec23d3489cf20ae66a2299d:/bin/starling.py?ds=sidebyside diff --git a/bin/starling.py b/bin/starling.py index 669cf06..ed745ee 100755 --- a/bin/starling.py +++ b/bin/starling.py @@ -12,11 +12,15 @@ class FeedError(Exception): def read_feed_item(i): try: - date = datetime.strptime(i["transactionTime"], "%Y-%m-%dT%H:%M:%S.%fZ") + if i.get("status", "") == "DECLINED": + return + date = datetime.strptime(i["transactionTime"], "%Y-%m-%dT%H:%M:%S.%f%z") amount = i["amount"]["minorUnits"] / 100 if i["direction"] == "OUT": amount = -amount payee = i["counterPartyName"] + if "counterPartySubEntityName" in i: + payee += " ({})".format(i["counterPartySubEntityName"]) reference = i.get("reference", payee) if outformat == "csv": print('{date:%Y-%m-%d},{amount},"{payee}","{description}","{notes}"'.format(date=date, @@ -25,7 +29,7 @@ def read_feed_item(i): description=reference, notes=reference)) elif outformat == "qif": - print("D{:%Y-%m-%d}".format(date)) + print("D{:%Y-%m-%d}".format(date.astimezone(None))) print("T{}".format(amount)) print("P{}".format(payee)) print("M{}".format(reference)) @@ -37,6 +41,9 @@ def read_feed_item(i): if __name__ == "__main__": if outformat == "qif": + print("!Account") + print("NCurrent Accounts:Starling") + print("^") print("!Type:Bank") cnt = 1 with open(sys.argv[1], 'r') if len(sys.argv) > 1 else sys.stdin as fp: