diff --git a/convert-sparkasse-to-homebank.py b/convert-sparkasse-to-homebank.py deleted file mode 100644 index e5bea44..0000000 --- a/convert-sparkasse-to-homebank.py +++ /dev/null @@ -1,33 +0,0 @@ -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.') diff --git a/sparkassecsv-camt-to-homebank.py b/sparkassecsv-camt-to-homebank.py new file mode 100644 index 0000000..a14fe5f --- /dev/null +++ b/sparkassecsv-camt-to-homebank.py @@ -0,0 +1,39 @@ +import sys +import csv +import re + +file_in = sys.argv[1] +ext_match = re.compile(re.escape('.csv'), re.IGNORECASE) +file_out = ext_match.sub('-converted.csv', file_in) +fieldnames = ['date', 'payment', 'info', 'payee', 'memo', 'amount', 'category', 'tags'] +print(f'Writing to {file_out}') +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 + try: + 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 + except: + e = sys.exc_info()[0] + print(e) + print(f'Processed {line_count} lines.')