From a47ee14d6847bf9d6e245548ca71087c4a73a197 Mon Sep 17 00:00:00 2001 From: luxick Date: Mon, 4 Jan 2021 17:55:40 +0100 Subject: [PATCH] Sparkasse to Homebank script Add script to convert Sparkasse transaction exports for import in Homebank --- .gitignore | 1 + convert-sparkasse-to-homebank.py | 33 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 .gitignore create mode 100644 convert-sparkasse-to-homebank.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a3062be --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode/* diff --git a/convert-sparkasse-to-homebank.py b/convert-sparkasse-to-homebank.py new file mode 100644 index 0000000..e5bea44 --- /dev/null +++ b/convert-sparkasse-to-homebank.py @@ -0,0 +1,33 @@ +import sys +import csv + +file_in = sys.argv[1] +file_out = file_in.replace('.csv', '-converted.csv') +fieldnames = ['date', 'payment', 'info', 'payee', 'memo', 'amount', 'category', 'tags'] + +with open(file_out, mode='w') as csv_out: + with open(file_in) as csv_file: + + writer = csv.DictWriter(csv_out, fieldnames=fieldnames) + writer.writeheader() + + reader = csv.reader(csv_file, delimiter=',') + line_count = 0 + for row in reader: + if line_count == 0: + line_count += 1 + continue + out_row = { + 'date': row[1], + 'payment': 0, + 'info': '', + 'payee': row[11], + 'memo': row[4], + 'amount': row[14], + 'category': '', + 'tags': '' + } + writer.writerow(out_row) + print(f'Converted: {out_row}') + line_count += 1 + print(f'Processed {line_count} lines.')