]> git.rmz.io Git - dotfiles.git/commitdiff
bin: update monzo and starling qif filters
authorSamir Benmendil <me@rmz.io>
Tue, 31 Jan 2023 23:33:09 +0000 (23:33 +0000)
committerSamir Benmendil <me@rmz.io>
Tue, 31 Jan 2023 23:35:21 +0000 (23:35 +0000)
* monzo to support both current and joint account
  * actual account_ids left out for privacy reasons
* starling to discard declined entries

bin/monzo.py
bin/starling.py

index e54aae5bce487a124b76309cfcf1a471ca405d14..722cc5f715956f58a583c4ec077ad058b8997abc 100755 (executable)
@@ -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
index 0941cbb2f69b163fcfbd7fe8d2a52ca7ac3dda9d..471cd1438310ff95f18affb11c8a6083feafbf8b 100755 (executable)
@@ -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":