Created
April 6, 2022 09:59
-
-
Save samueltc/1b8d14f6fb2ea71a8d0fad65321528dc 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
#!/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) | |
csv.writeheader() | |
for transaction in statement.transactions: | |
csv.writerow({ | |
'date': transaction.dtposted.strftime("%Y-%m-%d"), | |
'amount': str(transaction.trnamt), | |
'description': f'{transaction.name} ({transaction.memo})', | |
'reference': transaction.fitid | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment