Converter for ing diba transaction file to homebank csv format
authorAndreas Bilke <andreas@bilke.org>
Sun, 8 Oct 2017 16:09:45 +0000 (18:09 +0200)
committerAndreas Bilke <andreas@bilke.org>
Sun, 8 Oct 2017 16:10:17 +0000 (18:10 +0200)
banking/ingdiba2homebank.py [new file with mode: 0755]

diff --git a/banking/ingdiba2homebank.py b/banking/ingdiba2homebank.py
new file mode 100755 (executable)
index 0000000..5038a89
--- /dev/null
@@ -0,0 +1,30 @@
+#!/usr/bin/python3
+
+import argparse
+from datetime import datetime
+import sys
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser(description="Convert ING DiBa transaction to homebank csv format.")
+    parser.add_argument("csvfile", metavar="CSV", type=str, help="ING DiBA transaction file")
+
+    args = parser.parse_args()
+
+    csvfile = open(args.csvfile, encoding="latin-1")
+    csvfile.readline() # dismiss header
+
+    for line in csvfile:
+        fields = line.strip().split(";")
+        date = datetime.strptime(fields[2], "%d.%m.%Y")
+
+        if fields[4] == "0,00":
+            amount = fields[5]
+        elif fields[5] == "0,00":
+            amount = "-" + fields[4]
+        else:
+            print(("Cannot detect amount for line {}".format(line)), file=sys.stderr)
+
+        # date;payment;info;payee;memo;amount;category;tags
+        print(("{};{};{};{};{};{};{};{}".format(
+            date.strftime("%d-%m-%y"), "0", " ".join(fields[1].split()), "", " ".join(fields[1].split()), amount, "", ""
+        )))