Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support parsing quirky Chase QFX headers #160

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ofxparse/ofxparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,19 @@ def __init__(self, fh):

def read_headers(self):
head_data = self.fh.read(1024 * 10)
# Headers end at the first XML tag (starting with '<')
head_data = head_data[:head_data.find(six.b('<'))]

for line in head_data.splitlines():
# Newline?
if line.strip() == six.b(""):
continue

header, sep, value = line.partition(six.b(":"))
if len(sep) == 0:
# No ':' separator found, we probably reached the end of the headers
break

header, value = line.split(six.b(":"))
header, value = header.strip().upper(), value.strip()

self.headers[header] = value
Expand Down
62 changes: 62 additions & 0 deletions tests/fixtures/chase_cc.qfx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

OFXHEADER:100
DATA:OFXSGML
VERSION:102
SECURITY:NONE
ENCODING:USASCII
CHARSET:1252
COMPRESSION:NONE
OLDFILEUID:NONE
NEWFILEUID:NONE
<OFX>
<SIGNONMSGSRSV1>
<SONRS>
<STATUS>
<CODE>0
<SEVERITY>INFO
</STATUS>
<DTSERVER>20200102120000[0:GMT]
<LANGUAGE>ENG
<FI>
<ORG>B1
<FID>10898
</FI>
<INTU.BID>10898
</SONRS>
</SIGNONMSGSRSV1>
<CREDITCARDMSGSRSV1>
<CCSTMTTRNRS>
<TRNUID>1
<STATUS>
<CODE>0
<SEVERITY>INFO
<MESSAGE>Success
</STATUS>
<CCSTMTRS>
<CURDEF>USD
<CCACCTFROM>
<ACCTID>0123012301230123
</CCACCTFROM>
<BANKTRANLIST>
<DTSTART>20200101120000[0:GMT]
<DTEND>20200102120000[0:GMT]
<STMTTRN>
<TRNTYPE>DEBIT
<DTPOSTED>20200101120000[0:GMT]
<TRNAMT>-10.00
<FITID>2020010112341234123412341234123
<NAME>SQ *ECCO UN POCO ¦ NATURA
</STMTTRN>
</BANKTRANLIST>
<LEDGERBAL>
<BALAMT>-10.00
<DTASOF>20200102120000[0:GMT]
</LEDGERBAL>
<AVAILBAL>
<BALAMT>90.00
<DTASOF>20200102120000[0:GMT]
</AVAILBAL>
</CCSTMTRS>
</CCSTMTTRNRS>
</CREDITCARDMSGSRSV1>
</OFX>
6 changes: 6 additions & 0 deletions tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ def testMultipleAccounts(self):
self.assertEqual('CHECKING', ofx.accounts[0].account_type)
self.assertEqual('SAVINGS', ofx.accounts[1].account_type)

def testChaseCCNonAscii(self):
with open_file('chase_cc.qfx') as f:
ofx = OfxParser.parse(f)
self.assertEqual(1, len(ofx.account.statement.transactions))
self.assertEqual(Decimal('-10.00'), ofx.account.statement.transactions[0].amount)


class TestStringToDate(TestCase):
''' Test the string to date parser '''
Expand Down