Last active
July 19, 2024 20:32
-
-
Save z3ntu/c3009c20013ce0f9a32a831d477048ac to your computer and use it in GitHub Desktop.
Process csv file exported from ASN Bank to set account name
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
#!/usr/bin/env python3 | |
""" | |
ASN Bank CSV export doesn't contain any opposing account name for contactless | |
payments but contains the merchant name in the description field along with a | |
lot of other information. | |
We can split this description on the '>' chracter and extract the merchant | |
that way. | |
Idea adapted from: https://github.com/DanielsWrath/YNABGoingDutch/blob/3dcde360906bc87dc43efb62b0698f3f20d34519/js/bankMapper.js#L101-L111 | |
Relevant CSV field descriptions from document "Bestandsbeschrijving export | |
bestand ASN Online Bankieren" | |
[3]: Naam tegenrekening | |
[17]: Omschrijving | |
""" | |
import csv | |
import sys | |
if len(sys.argv) != 2: | |
print(f"Usage: {sys.argv[0]} FILE.csv") | |
sys.exit(1) | |
with open(sys.argv[1], newline='') as csvfile: | |
reader = csv.reader(csvfile, delimiter=',', quotechar='\'') | |
writer = csv.writer(sys.stdout, delimiter=',', quotechar='\'') | |
for row in reader: | |
# Check if oppposing account name is empty | |
if not row[3]: | |
# Split description on '>' character | |
parts = row[17].split('>') | |
if len(parts) == 2: | |
# Get account name from first part - set as opposing account name | |
row[3] = parts[0].strip() | |
else: | |
print(f"Expected two parts from string, ignoring. Got: {parts}", file=sys.stderr) | |
# Write new row to new csv | |
writer.writerow(row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment