コード例 #1
0
 def test_02_opening_tag_file(self):
     '''
     Parse a basic set of tokens
     '''
     parser = OFXParser(open(self.path + 'opening_tag.ofx').read())
     tag = parser._read_tag()
     self.assertTrue(tag.type == tag.TYPE_OPENING)
     self.assertTrue(tag.name == 'STATUS')
コード例 #2
0
 def test_07_parse_real_file_and_render_as_xml(self):
     '''
     Parse a real file
     '''
     parser = OFXParser(open(self.path+'real_file_no_headers.ofx').read())
     ofx_tree = parser.parse()
     
     print ofx_tree.xml_repr()
コード例 #3
0
 def test_02_opening_tag_file(self):
     '''
     Parse a basic set of tokens
     '''
     parser = OFXParser(open(self.path+'opening_tag.ofx').read())
     tag = parser._read_tag()
     self.assertTrue(tag.type==tag.TYPE_OPENING)
     self.assertTrue(tag.name=='STATUS')
コード例 #4
0
    def test_07_parse_real_file_and_render_as_xml(self):
        '''
        Parse a real file
        '''
        parser = OFXParser(open(self.path + 'real_file_no_headers.ofx').read())
        ofx_tree = parser.parse()

        print ofx_tree.xml_repr()
コード例 #5
0
 def test_04_selfclosing_tag_file(self):
     '''
     Parse a basic set of tokens
     '''
     parser = OFXParser(open(self.path+'selfclosing_tag.ofx').read())
     tag = parser._read_tag()
     self.assertTrue(tag.type==tag.TYPE_SELFCLOSING)
     self.assertTrue(tag.name=='CODE')
     self.assertTrue(tag.value=='this is a value with 1 number and 2 special chars :(')
コード例 #6
0
 def test_08_parse_real_file(self):
     '''
     Parse a real file
     '''
     parser = OFXParser(open(self.path+'real_file_no_headers.ofx').read())
     OFX = parser.parse()
     sl = render_as_DOT(OFX)
     print
     for e in sl:
         print e.export_as_csv()
コード例 #7
0
 def test_04_selfclosing_tag_file(self):
     '''
     Parse a basic set of tokens
     '''
     parser = OFXParser(open(self.path + 'selfclosing_tag.ofx').read())
     tag = parser._read_tag()
     self.assertTrue(tag.type == tag.TYPE_SELFCLOSING)
     self.assertTrue(tag.name == 'CODE')
     self.assertTrue(tag.value ==
                     'this is a value with 1 number and 2 special chars :(')
コード例 #8
0
 def test_06_parse_real_file_as_token_list(self):
     """
     Parse a real file
     """
     parser = OFXParser(open(self.path+'real_file_no_headers.ofx').read())
     print
     tag = parser._read_tag()
     while tag is not None:
         print "%-20s|%-20s|%s " % (tag.get_type_name(), tag.name, tag.value )
         tag = parser._read_tag()
コード例 #9
0
 def test_05_real_ofx_content(self):
     """
     Parse a basic set of tokens
     """
     parser = OFXParser(open(self.path+'real_file_no_headers.ofx').read())
     OFX = parser.parse()
     try:
         print OFX.BANKMSGSRSV1.notag
     except AttributeError, msg:
         self.assertTrue(msg.message=="OFX.BANKMSGSRSV1 has no 'notag' child node.")
コード例 #10
0
 def test_09_parse_then_inspect_headers_then_content(self):
     """
     Open a real file, parse it, then inspect headers, then content
     """
     parser = OFXParser(open(self.path+'real_file_with_headers.ofx','U').read())
     OFX = parser.parse()
     print "\nTest 9: parse then inspect headers and content:"
     self.assertTrue(parser.OFX_headers['VERSION']=='102')
     self.assertTrue(parser.OFX_headers['CHARSET']=='1252')
     self.assertTrue( OFX.BANKMSGSRSV1.STMTTRNRS.TRNUID.val == '41425367824' )
コード例 #11
0
 def test_08_parse_real_file(self):
     '''
     Parse a real file
     '''
     parser = OFXParser(open(self.path + 'real_file_no_headers.ofx').read())
     OFX = parser.parse()
     sl = render_as_DOT(OFX)
     print
     for e in sl:
         print e.export_as_csv()
コード例 #12
0
    def test_03_parse_obfuscated_file_and_save_as_ofx(self):
        '''
        Use filemerge to compare : output/real_file_obfuscated.ofx
        and output/real_file_obfuscated_2.ofx
        '''
        parser = OFXParser(open('output/real_file_obfuscated.ofx').read())
        OFX = parser.parse()

        f = open('output/real_file_obfuscated_2.ofx','w')
        f.write(OFX.ofx_repr())
        f.close()
コード例 #13
0
 def test_09_parse_then_inspect_headers_then_content(self):
     """
     Open a real file, parse it, then inspect headers, then content
     """
     parser = OFXParser(
         open(self.path + 'real_file_with_headers.ofx', 'U').read())
     OFX = parser.parse()
     print "\nTest 9: parse then inspect headers and content:"
     self.assertTrue(parser.OFX_headers['VERSION'] == '102')
     self.assertTrue(parser.OFX_headers['CHARSET'] == '1252')
     self.assertTrue(OFX.BANKMSGSRSV1.STMTTRNRS.TRNUID.val == '41425367824')
コード例 #14
0
    def test_03_parse_obfuscated_file_and_save_as_ofx(self):
        '''
        Use filemerge to compare : output/real_file_obfuscated.ofx
        and output/real_file_obfuscated_2.ofx
        '''
        parser = OFXParser(open('output/real_file_obfuscated.ofx').read())
        OFX = parser.parse()

        f = open('output/real_file_obfuscated_2.ofx', 'w')
        f.write(OFX.ofx_repr())
        f.close()
コード例 #15
0
 def test_07_parse_ofx_headers_only(self):
     """
     Parse a real file and extract headers
     """
     parser = OFXParser(open(self.path+'real_file_with_headers.ofx','U').read())
     parser.parse_headers()
     print "\nTest 7: Dumping headers:"
     for h in parser.OFX_headers.items():
         print "-",h
     self.assertTrue(parser.OFX_headers['VERSION']=='102')
     self.assertTrue(parser.OFX_headers['CHARSET']=='1252')
コード例 #16
0
 def test_06_parse_real_file_as_token_list(self):
     """
     Parse a real file
     """
     parser = OFXParser(open(self.path + 'real_file_no_headers.ofx').read())
     print
     tag = parser._read_tag()
     while tag is not None:
         print "%-20s|%-20s|%s " % (tag.get_type_name(), tag.name,
                                    tag.value)
         tag = parser._read_tag()
コード例 #17
0
 def test_05_real_ofx_content(self):
     """
     Parse a basic set of tokens
     """
     parser = OFXParser(open(self.path + 'real_file_no_headers.ofx').read())
     OFX = parser.parse()
     try:
         print OFX.BANKMSGSRSV1.notag
     except AttributeError, msg:
         self.assertTrue(
             msg.message == "OFX.BANKMSGSRSV1 has no 'notag' child node.")
コード例 #18
0
    def test_05_parse_obfuscatedreal_and_save_as_xml(self):
        '''
        This test use OFXNode.obfuscated_ofx_repr() which generates a usable OFX
        '''
        src = open('output/multi_account_obfuscated.ofx')
        parser = OFXParser(src.read())
        src.close()

        OFX = parser.parse()
        f = open('output/multi_account_obfuscated.xml', 'w')
        f.write(OFX.xml_repr())
        f.close()
コード例 #19
0
    def test_05_parse_obfuscatedreal_and_save_as_xml(self):
        '''
        This test use OFXNode.obfuscated_ofx_repr() which generates a usable OFX
        '''
        src = open('output/multi_account_obfuscated.ofx')
        parser = OFXParser(src.read())
        src.close()

        OFX =parser.parse()
        f = open('output/multi_account_obfuscated.xml','w')
        f.write(OFX.xml_repr())
        f.close()
コード例 #20
0
 def test_07_parse_ofx_headers_only(self):
     """
     Parse a real file and extract headers
     """
     parser = OFXParser(
         open(self.path + 'real_file_with_headers.ofx', 'U').read())
     parser.parse_headers()
     print "\nTest 7: Dumping headers:"
     for h in parser.OFX_headers.items():
         print "-", h
     self.assertTrue(parser.OFX_headers['VERSION'] == '102')
     self.assertTrue(parser.OFX_headers['CHARSET'] == '1252')
コード例 #21
0
ファイル: ofxplode.py プロジェクト: cmorisse/inouk.edofx
def main(source_file):
    """
        Takes a multi-account OFX file as input and
        output one OFX file per account.
    """
    f = open(source_file)
    p = OFXParser(f.read())
    o = p.parse()

    # on vire les infos sur les cartes de crédits
    try:
        del o.CREDITCARDMSGSRSV1
    except:
        pass

    # first we backup all account information
    account_list = list()
    for e in o.BANKMSGSRSV1.STMTTRNRS:
        account_list.append(e)

    # we wipe all accounts
    del o.BANKMSGSRSV1.STMTTRNRS

    for e in account_list:
        o.BANKMSGSRSV1.children.append(e)
        for t in o.BANKMSGSRSV1.STMTTRNRS.STMTRS.BANKTRANLIST.STMTTRN:
            t.TRNTYPE.value = t.MEMO.value  # update transaction type
            t.MEMO.value = ''
            if t.TRNTYPE.value == 'PAIEMENT PAR CARTE':
                t.MEMO.value = "Operation du %s" % (t.NAME.value[-5:], )
                t.NAME.value = t.NAME.value[:-5].lstrip().rstrip()
            elif t.TRNTYPE.value == 'REMBOURSEMENT DE PRET':
                t.MEMO.value = "Echeance du %s " % (t.NAME.value[-8:], )
                t.NAME.value = t.NAME.value[:-8].lstrip().rstrip()

        fofx = open(
            'compte_%s_from_%s_to_%s.ofx' %
            (e.STMTRS.BANKACCTFROM.ACCTID.val,
             e.STMTRS.BANKTRANLIST.DTSTART.value[:8],
             e.STMTRS.BANKTRANLIST.DTEND.value[:8]), 'w')
        fofx.write(o.ofx_repr())
        fofx.close()

        fxml = open(
            'compte_%s_from_%s_to_%s.xml' %
            (e.STMTRS.BANKACCTFROM.ACCTID.val,
             e.STMTRS.BANKTRANLIST.DTSTART.value[:8],
             e.STMTRS.BANKTRANLIST.DTEND.value[:8]), 'w')
        fxml.write(o.xml_repr())
        fxml.close()

        del o.BANKMSGSRSV1.STMTTRNRS
コード例 #22
0
    def test_09_parse_multi_acct_file_and_export_as_xml(self):
        '''
        Parse a real file
        '''
        src = open(self.path+'multi_account_file.ofx')
        parser = OFXParser(src.read())
        src.close()
        
        OFX = parser.parse()

        f = open('output/test_09_output_as_xml.xml','w')
        f.write(OFX.xml_repr())
        f.close()
コード例 #23
0
    def test_09_parse_multi_acct_file_and_export_as_xml(self):
        '''
        Parse a real file
        '''
        src = open(self.path + 'multi_account_file.ofx')
        parser = OFXParser(src.read())
        src.close()

        OFX = parser.parse()

        f = open('output/test_09_output_as_xml.xml', 'w')
        f.write(OFX.xml_repr())
        f.close()
コード例 #24
0
ファイル: edofx2csv.py プロジェクト: cmorisse/inouk.edofx
def main(source_file):
    """
        Takes a multi-account OFX file as input and
        output one OFX file per account.
    """
    f = open(source_file)
    p = OFXParser(f.read())
    o = p.parse()
    
    statement_list = build_Statement_tree(o) 
    
    for stmt in statement_list:
        file_name =  'releve_compte_'+stmt.account_id.strip()+'_du_'+str(stmt.start_date.strftime("%d-%m-%Y"))+'_au_'+str(stmt.end_date.strftime("%d-%m-%Y"))+'.csv'
        f = open(file_name,'w')
        f.write(stmt.export_as_csv())
        f.close()
コード例 #25
0
ファイル: ofxplode.py プロジェクト: cmorisse/inouk.edofx
def main(source_file):
    """
        Takes a multi-account OFX file as input and
        output one OFX file per account.
    """
    f = open(source_file)
    p = OFXParser(f.read())
    o = p.parse()
    
    # on vire les infos sur les cartes de crédits
    try:
        del o.CREDITCARDMSGSRSV1
    except:
        pass    
    
    # first we backup all account information
    account_list = list() 
    for e in o.BANKMSGSRSV1.STMTTRNRS:
        account_list.append(e)

    # we wipe all accounts
    del o.BANKMSGSRSV1.STMTTRNRS
 
    for e in account_list:
        o.BANKMSGSRSV1.children.append(e)
        for t in o.BANKMSGSRSV1.STMTTRNRS.STMTRS.BANKTRANLIST.STMTTRN:
            t.TRNTYPE.value = t.MEMO.value # update transaction type
            t.MEMO.value = ''
            if t.TRNTYPE.value == 'PAIEMENT PAR CARTE' :
                t.MEMO.value = "Operation du %s" % (t.NAME.value[-5:],)
                t.NAME.value = t.NAME.value[:-5].lstrip().rstrip() 
            elif t.TRNTYPE.value == 'REMBOURSEMENT DE PRET' :
                t.MEMO.value = "Echeance du %s " % (t.NAME.value[-8:],)
                t.NAME.value = t.NAME.value[:-8].lstrip().rstrip() 
                
            
        
        fofx = open('compte_%s_from_%s_to_%s.ofx' %  (e.STMTRS.BANKACCTFROM.ACCTID.val, e.STMTRS.BANKTRANLIST.DTSTART.value[:8], e.STMTRS.BANKTRANLIST.DTEND.value[:8] ),'w')
        fofx.write(o.ofx_repr())
        fofx.close()
        
        fxml = open('compte_%s_from_%s_to_%s.xml' %  (e.STMTRS.BANKACCTFROM.ACCTID.val, e.STMTRS.BANKTRANLIST.DTSTART.value[:8], e.STMTRS.BANKTRANLIST.DTEND.value[:8] ),'w')
        fxml.write(o.xml_repr())
        fxml.close()

        del o.BANKMSGSRSV1.STMTTRNRS
コード例 #26
0
    def test_11_parse_multi_acct_file_and_export_as_several_csv(self):
        '''
        Parse a real file and export as many individual csv files
        '''
        src = open(self.path+'multi_account_file.ofx')
        parser = OFXParser(src.read())
        src.close()
        
        OFX = parser.parse()

        statement_list = render_as_DOT(OFX)

        for e in statement_list:
            file_name =  'output/'+e.account_id.strip()+'_statement from_'+str(e.start_date)+'_to_'+str(e.end_date)+'.csv'
            f = open(file_name,'w')
            f.write(e.export_as_csv())
            f.close()
            print e.export_as_csv()            
コード例 #27
0
def main(source_file):
    """
        Takes a multi-account OFX file as input and
        output one OFX file per account.
    """
    f = open(source_file)
    p = OFXParser(f.read())
    o = p.parse()

    statement_list = build_Statement_tree(o)

    for stmt in statement_list:
        file_name = 'releve_compte_' + stmt.account_id.strip() + '_du_' + str(
            stmt.start_date.strftime("%d-%m-%Y")) + '_au_' + str(
                stmt.end_date.strftime("%d-%m-%Y")) + '.csv'
        f = open(file_name, 'w')
        f.write(stmt.export_as_csv())
        f.close()
コード例 #28
0
    def test_10_parse_realfile_and_re_export_it_as_ofx(self):
        '''
        Parse a real file and export it again as OFX
        
        Use a file diff tool to compare test_10_output_as_ofx.ofx with real_file.ofx
        
        On Unix/MacOS files should be identical.
        On Windows, we may have CR/LF differences. 
        
        '''
        src = open(self.path+'real_file_no_headers.ofx')
        parser = OFXParser(src.read())
        src.close()
        
        OFX = parser.parse()

        f = open('output/test_12_output_as_ofx.ofx','w')
        f.write(OFX.ofx_repr())
        f.close()
コード例 #29
0
    def test_10_parse_realfile_and_re_export_it_as_ofx(self):
        '''
        Parse a real file and export it again as OFX
        
        Use a file diff tool to compare test_10_output_as_ofx.ofx with real_file.ofx
        
        On Unix/MacOS files should be identical.
        On Windows, we may have CR/LF differences. 
        
        '''
        src = open(self.path + 'real_file_no_headers.ofx')
        parser = OFXParser(src.read())
        src.close()

        OFX = parser.parse()

        f = open('output/test_12_output_as_ofx.ofx', 'w')
        f.write(OFX.ofx_repr())
        f.close()
コード例 #30
0
    def test_11_parse_multi_acct_file_and_export_as_several_csv(self):
        '''
        Parse a real file and export as many individual csv files
        '''
        src = open(self.path + 'multi_account_file.ofx')
        parser = OFXParser(src.read())
        src.close()

        OFX = parser.parse()

        statement_list = render_as_DOT(OFX)

        for e in statement_list:
            file_name = 'output/' + e.account_id.strip(
            ) + '_statement from_' + str(e.start_date) + '_to_' + str(
                e.end_date) + '.csv'
            f = open(file_name, 'w')
            f.write(e.export_as_csv())
            f.close()
            print e.export_as_csv()
コード例 #31
0
 def test_01_empty_ofx_file(self):
     try:
         parser = OFXParser(open(self.path + 'empty.ofx').read())
     except Exception as e:
         self.assertTrue(e.message.__contains__("Invalid source string"))
コード例 #32
0
 def test_03_closing_tag_file(self):
     """Test self closing tag parsing"""
     parser = OFXParser(open(self.path + 'closing_tag.ofx').read())
     tag = parser._read_tag()
     self.assertTrue(tag.type == tag.TYPE_CLOSING)
     self.assertTrue(tag.name == 'STATUS')
コード例 #33
0
 def test_03_closing_tag_file(self):
     """Test self closing tag parsing"""
     parser = OFXParser(open(self.path+'closing_tag.ofx').read())
     tag = parser._read_tag()
     self.assertTrue(tag.type==tag.TYPE_CLOSING)
     self.assertTrue(tag.name=='STATUS')