def _init(self, invstmtrs): dtasof = invstmtrs.find('DTASOF').text self.datetime = types.DateTime.convert(dtasof) # INVTRANLIST tranlist = invstmtrs.find('INVTRANLIST') if tranlist is not None: self.transactions = INVTRANLIST(tranlist) # INVPOSLIST poslist = invstmtrs.find('INVPOSLIST') if poslist is not None: self.positions = [Aggregate.from_etree(pos) for pos in poslist] # INVBAL invbal = invstmtrs.find('INVBAL') if invbal is not None: # First strip off BALLIST & process it ballist = invbal.find('BALLIST') if ballist is not None: invbal.remove(ballist) self.other_balances = [Aggregate.from_etree(bal) for bal in ballist] # Now we can flatten the rest of INVBAL self.balances = Aggregate.from_etree(invbal) # Unsupported subaggregates for tag in ('INVOOLIST', 'INV401K', 'INV401KBAL', 'MKTGINFO'): child = invstmtrs.find(tag) if child is not None: invstmtrs.remove
def copyTRNRS(self, trnrs): """ Attach the data fields from the *TRNRS wrapper to the STMT """ self.uid = types.String(36).convert(trnrs.find('TRNUID').text) self.status = Aggregate.from_etree(trnrs.find('STATUS')) cltcookie = trnrs.find('CLTCOOKIE') if cltcookie is not None: self.cookie = types.String(36).convert(cltcookie.text)
def __init__(self, tranlist): # Initialize with *TRANLIST Element dtstart, dtend = tranlist[0:2] tranlist = tranlist[2:] self.dtstart = types.DateTime.convert(dtstart.text) self.dtend = types.DateTime.convert(dtend.text) self.extend([Aggregate.from_etree(tran) for tran in tranlist])
def __init__(self, tree, strict=True): """ Initialize with ofx.ElementTree instance containing parsed OFX. The strict argument determines whether to throw an error for certain OFX data validation violations. """ # Keep a copy of the parse tree self.tree = tree # SONRS - server response to signon request sonrs = self.tree.find('SIGNONMSGSRSV1/SONRS') self.sonrs = Aggregate.from_etree(sonrs, strict=strict) # TRNRS - transaction response, which is the main section # containing account statements # # N.B. This iteration method doesn't preserve the original # ordering of the statements within the OFX response for stmtClass in (BankStatement, CreditCardStatement, InvestmentStatement): tagname = stmtClass._tagName for trnrs in self.tree.findall('*/%sTRNRS' % tagname): # *STMTTRNRS may have no *STMTRS (in case of error). # Don't blow up; skip silently. stmtrs = trnrs.find('%sRS' % tagname) if stmtrs is not None: stmt = stmtClass(stmtrs) # Staple the TRNRS wrapper data onto the STMT stmt.copyTRNRS(trnrs) self.statements.append(stmt) # SECLIST - list of description of securities referenced by # INVSTMT (investment account statement) seclist = self.tree.find('SECLISTMSGSRSV1/SECLIST') if seclist is None: return for sec in seclist: self.securities.append(Aggregate.from_etree(sec, strict=strict))
def _init(self, stmtrs): # BANKTRANLIST tranlist = stmtrs.find('BANKTRANLIST') if tranlist is not None: self.transactions = BANKTRANLIST(tranlist) # LEDGERBAL - mandatory self.ledgerbal = Aggregate.from_etree(stmtrs.find('LEDGERBAL')) # AVAILBAL availbal = stmtrs.find('AVAILBAL') if availbal is not None: self.availbal = Aggregate.from_etree(availbal) # BALLIST ballist = stmtrs.find('BALLIST') if ballist: self.other_balances = [Aggregate.from_etree(bal) for bal in ballist] # Unsupported subaggregates for tag in ('MKTGINFO', ): child = stmtrs.find(tag) if child: stmtrs.remove
def __init__(self, stmtrs): """ Initialize with *STMTRS Element """ self.currency = stmtrs.find('CURDEF').text self.account = Aggregate.from_etree(stmtrs.find(self._acctTag)) self._init(stmtrs)