Created
October 8, 2022 19:15
-
-
Save j4velin/d9dadf8b918bcb13d2e70bcca3f6cc9d to your computer and use it in GitHub Desktop.
DKB -> Firefly CSV Converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# -*- coding: utf-8 -*- | |
import os | |
import csv | |
import re | |
accounts = [ "add account numbers here" ] | |
def handleAccount(input): | |
with open(input, 'r', encoding='ISO-8859-1', newline='') as infile: | |
firstLine = infile.readline() | |
accountName = re.search('.* / (.*)";', firstLine, re.IGNORECASE).group(1) | |
with open(accountName + '.csv', 'w', encoding='UTF-8', newline='') as outfile: | |
csvwriter = csv.writer(outfile, delimiter=';', quoting=csv.QUOTE_ALL) | |
csvreader = csv.reader(infile, delimiter=';') | |
for row in csvreader: | |
if len(row) >= 7: | |
# transfers between both accounts show up in both files -> skip from one | |
# to avoid duplicates in Firefly | |
if accounts[1] in input and "12030000" + account[0] in row[5]: | |
print('Skipping ' + row[4] + ' to avoid duplicates\n') | |
continue | |
# invalid BIC in stock purchases | |
if row[6] == "12030000" or row[6] == "0": | |
row[6] = "BYLADEM1001" | |
# Visa debit card workaround | |
if "Debitk." in row[4]: | |
row[4] = row[3] + " " + row[4] | |
csvwriter.writerow(row) | |
os.remove(input) | |
for account in accounts: | |
handleAccount(account + '.csv') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment