Last active
July 19, 2023 11:04
-
-
Save stevedep/b77a86f86ce5abda6cac7faa785b8525 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from datetime import datetime | |
import csv | |
pad = "/home/steve/Documents/Transacties/CSV_CC_6606_20230401_20230718.csv" | |
with open(pad, 'r') as csv_file: | |
csv_reader = csv.reader(csv_file) | |
transactions = list(csv_reader) | |
mt940 = ":940:\n" | |
# remove first linke from transactions | |
rownumber = 1 | |
for transaction in transactions[1:len(transactions)]: | |
# Assuming CSV columns are: date, amount, description | |
date = transaction[7] | |
amount = transaction[8] | |
description = transaction[9] | |
date_string = date | |
date_obj = datetime.strptime(date_string, "%Y-%m-%d") | |
formatted_date = date_obj.strftime("%y%m%d") | |
# Constructing MT940 transaction line | |
# add :20940S with the date formatted as YYMMDD | |
# append 00000000000000 to amount and then take the last 15 characters | |
# remove sign from amount | |
amount = amount[1:] | |
amount = "00000000000000" + str(amount) | |
amount = amount[-15:] | |
# if description contains "IFTTT" then perform some code | |
if "IFTTT" in description: | |
mt940 += ":20:940S" + formatted_date + "\n" | |
mt940 += ":25:JEBANKREKENINGNUMMER EUR\n" | |
mt940 += ":28C:"+ str(rownumber) +"\n" | |
mt940 += ":60F:C" + formatted_date + "EUR000000000000\n" | |
mt940 += ":61:"+ formatted_date + "D" + amount + "N030NONREF\n" | |
mt940 += ":86:/TRCD/030/BENM//NAME/" + description + "\n" | |
mt940 += ":62F:C" + formatted_date + "EUR000000000000\n" | |
# increment rownumber | |
rownumber += 1 | |
# store mt940 in a file | |
with open("/media/sf_Downloads3/mt940.swi", "w") as text_file: | |
text_file.write(mt940) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment