Convert hello bank! csv to homebank
authorAndreas Bilke <andreas@bilke.org>
Fri, 8 Dec 2017 19:00:54 +0000 (20:00 +0100)
committerAndreas Bilke <andreas@bilke.org>
Fri, 8 Dec 2017 19:00:54 +0000 (20:00 +0100)
banking/hellobank2homebank.py [new file with mode: 0755]

diff --git a/banking/hellobank2homebank.py b/banking/hellobank2homebank.py
new file mode 100755 (executable)
index 0000000..e9bbbe3
--- /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 Hello bank! transaction to homebank csv format.")
+    parser.add_argument("csvfile", metavar="CSV", type=str, help="Hello bank! 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(";")
+        try:
+            date = datetime.strptime(fields[2], "%Y-%m-%d")
+        except ValueError as e:
+            print(("Cannot convert line\n{}\n".format(line)), file=sys.stderr)
+            continue
+
+        amount = fields[7].replace(".", "")
+        text = " ".join(fields[9].replace("\"", "").split())
+
+        # date;payment;info;payee;memo;amount;category;tags
+        print(("{};{};{};{};{};{};{};{}".format(
+            date.strftime("%d-%m-%y"), "0", "", "", text, amount, "", ""
+        )))