Skip to content

Instantly share code, notes, and snippets.

Created Apr 6, 2022
What would you like to do?
#!/usr/bin/env python
from ofxtools.Parser import OFXTree
from csv import DictWriter
from glob import glob
import sys
HEADER = ('date', 'amount', 'description', 'reference')
parser = OFXTree()
for filename in glob(sys.argv[1]):
print ('filename', filename)
parser.parse(open(filename, 'rb'))
ofx = parser.convert()
statements = ofx.statements
for statement in statements:
print ('>>>', statement.acctid)
filename = f'{statement.acctid}.csv'
csv = DictWriter(open(filename, 'w'), fieldnames=HEADER)
for transaction in statement.transactions:
'date': transaction.dtposted.strftime("%Y-%m-%d"),
'amount': str(transaction.trnamt),
'description': f'{} ({transaction.memo})',
'reference': transaction.fitid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment