Created
June 20, 2014 19:01
-
-
Save mxey/f7d872f4770ebabec9a3 to your computer and use it in GitHub Desktop.
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
import csv | |
from datetime import datetime | |
import sys | |
mt940_reader = csv.DictReader(sys.stdin, delimiter=';') | |
ynab_writer = csv.DictWriter(sys.stdout, fieldnames=('Date', 'Payee', 'Category', 'Memo', 'Outflow', 'Inflow')) | |
ynab_writer.writeheader() | |
for mt940_row in mt940_reader: | |
valuation_date = datetime.strptime(mt940_row['Valutadatum'], '%d.%m.%y') | |
value = float(mt940_row['Betrag'].replace(',', '.')) | |
ynab_row = { | |
'Date': valuation_date.strftime('%d/%m/%y'), | |
'Payee': mt940_row['Beguenstigter/Zahlungspflichtiger'], | |
'Memo': mt940_row['Buchungstext'], | |
} | |
if value > 0: | |
ynab_row['Inflow'] = value | |
else: | |
ynab_row['Outflow'] = abs(value) | |
ynab_writer.writerow(ynab_row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment