Пример #1
0
def sync(ledger, accounts, args):
    sync = OfxSynchronizer(ledger, shortenaccount=args.shortenaccount)
    for acct in accounts:
        try:
            (ofx, txns) = sync.get_new_txns(acct,
                                            resync=args.resync,
                                            max_days=args.max)
            if ofx is not None:
                converter = make_ofx_converter(
                    account=ofx.account,
                    name=acct.description,
                    ledger=ledger,
                    indent=args.indent,
                    fid=None,
                    unknownaccount=args.unknownaccount,
                    payee_format=args.payee_format,
                    hardcodeaccount=None,
                    shortenaccount=args.shortenaccount,
                    security_list=SecurityList(ofx),
                    date_format=args.date_format,
                    infer_account=args.infer_account)
                print_results(converter, ofx, ledger, txns, args)
        except KeyboardInterrupt:
            raise
        except BaseException:
            sys.stderr.write("Caught exception processing %s\n" %
                             (acct.description))
            traceback.print_exc(file=sys.stderr)
Пример #2
0
 def test_apostrophe(self):
     ofxpath = os.path.join('fixtures', 'apostrophe.ofx')
     ofx = OfxSynchronizer.parse_file(ofxpath)
     sync = OfxSynchronizer(self.lgr)
     txns = sync.filter(ofx.account.statement.transactions,
                        ofx.account.account_id)
     self.assertEquals(len(txns), 1)
Пример #3
0
 def test_all_new_txns(self):
     ledger = Ledger(os.path.join('fixtures', 'empty.lgr'))
     acct = Mock()
     acct.download = Mock(
         return_value=file(os.path.join('fixtures', 'checking.ofx')))
     sync = OfxSynchronizer(ledger)
     self.assertEqual(len(sync.get_new_txns(acct, 7, 7)[1]), 3)
Пример #4
0
 def test_one_settleDate(self):
     ofxpath = os.path.join('fixtures', 'fidelity-one-dtsettle.ofx')
     ofx = OfxSynchronizer.parse_file(ofxpath)
     sync = OfxSynchronizer(self.lgr)
     txns = sync.filter(ofx.account.statement.transactions,
                        ofx.account.account_id)
     self.assertEquals(len(txns), 17)
Пример #5
0
 def test_fresh_sync(self):
     ledger = Ledger(os.path.join('fixtures', 'empty.lgr'))
     sync = OfxSynchronizer(ledger)
     ofx = OfxParser.parse(file(os.path.join('fixtures', 'checking.ofx')))
     txns1 = ofx.account.statement.transactions
     txns2 = sync.filter(ofx)
     self.assertEqual(txns1, txns2)
Пример #6
0
def import_ofx(ledger, args):
    sync = OfxSynchronizer(ledger, hardcodeaccount=args.hardcodeaccount,
                           shortenaccount=args.shortenaccount)
    ofx = OfxSynchronizer.parse_file(args.PATH)
    txns = sync.filter(
        ofx.account.statement.transactions,
        ofx.account.account_id)
    accountname = args.account
    if accountname is None:
        if ofx.account.institution is not None:
            accountname = "%s:%s" % (ofx.account.institution.organization,
                                     ofx.account.account_id)
        else:
            accountname = UNKNOWN_BANK_ACCOUNT

    # build SecurityList (including indexing by CUSIP and ticker symbol)
    security_list = SecurityList(ofx)

    converter = make_ofx_converter(account=ofx.account,
                                   name=accountname,
                                   ledger=ledger,
                                   indent=args.indent,
                                   fid=args.fid,
                                   unknownaccount=args.unknownaccount,
                                   payee_format=args.payee_format,
                                   hardcodeaccount=args.hardcodeaccount,
                                   shortenaccount=args.shortenaccount,
                                   security_list=security_list)
    print_results(converter, ofx, ledger, txns, args)
Пример #7
0
 def test_fresh_sync(self):
     ledger = Ledger(os.path.join('fixtures', 'empty.lgr'))
     sync = OfxSynchronizer(ledger)
     ofx = OfxParser.parse(open(os.path.join('fixtures', 'checking.ofx')))
     txns1 = ofx.account.statement.transactions
     txns2 = sync.filter(txns1, ofx.account.account_id)
     self.assertEqual(txns1, txns2)
Пример #8
0
 def test_no_institution(self):
     ofxpath = os.path.join('fixtures', 'no-institution.ofx')
     sync = OfxSynchronizer(self.lgr)
     ofx = OfxSynchronizer.parse_file(ofxpath)
     txns = sync.filter(ofx.account.statement.transactions,
                        ofx.account.account_id)
     self.assertEquals(len(txns), 3)
Пример #9
0
def import_ofx(ledger, args):
    sync = OfxSynchronizer(ledger,
                           hardcodeaccount=args.hardcodeaccount,
                           shortenaccount=args.shortenaccount)
    ofx = OfxSynchronizer.parse_file(args.PATH)
    txns = sync.filter(ofx.account.statement.transactions,
                       ofx.account.account_id)
    accountname = args.account
    if accountname is None:
        if ofx.account.institution is not None:
            accountname = "%s:%s" % (ofx.account.institution.organization,
                                     ofx.account.account_id)
        else:
            accountname = UNKNOWN_BANK_ACCOUNT

    # build SecurityList (including indexing by CUSIP and ticker symbol)
    security_list = SecurityList(ofx)

    converter = make_ofx_converter(account=ofx.account,
                                   name=accountname,
                                   ledger=ledger,
                                   indent=args.indent,
                                   fid=args.fid,
                                   unknownaccount=args.unknownaccount,
                                   payee_format=args.payee_format,
                                   hardcodeaccount=args.hardcodeaccount,
                                   shortenaccount=args.shortenaccount,
                                   security_list=security_list,
                                   date_format=args.date_format,
                                   infer_account=args.infer_account)
    print_results(converter, ofx, ledger, txns, args)
Пример #10
0
 def test_comment_txns(self):
     ledger = Ledger(os.path.join('fixtures', 'empty.lgr'))
     sync = OfxSynchronizer(ledger)
     ofx = OfxSynchronizer.parse_file(
         os.path.join('fixtures', 'comments.ofx'))
     txns = sync.filter(ofx.account.statement.transactions,
                        ofx.account.account_id)
     self.assertEqual(len(txns), 1)
Пример #11
0
 def test_apostrophe(self):
     ofxpath = os.path.join('fixtures', 'apostrophe.ofx')
     ofx = OfxSynchronizer.parse_file(ofxpath)
     sync = OfxSynchronizer(self.lgr)
     txns = sync.filter(
         ofx.account.statement.transactions,
         ofx.account.account_id)
     self.assertEqual(len(txns), 1)
Пример #12
0
 def test_one_settleDate(self):
     ofxpath = os.path.join('fixtures', 'fidelity-one-dtsettle.ofx')
     ofx = OfxSynchronizer.parse_file(ofxpath)
     sync = OfxSynchronizer(self.lgr)
     txns = sync.filter(
         ofx.account.statement.transactions,
         ofx.account.account_id)
     self.assertEqual(len(txns), 17)
Пример #13
0
 def test_partial_sync(self):
     ledger = Ledger(os.path.join('fixtures', 'checking-partial.lgr'))
     sync = OfxSynchronizer(ledger)
     ofx = OfxSynchronizer.parse_file(
         os.path.join('fixtures', 'checking.ofx'))
     txns = sync.filter(ofx.account.statement.transactions,
                        ofx.account.account_id)
     self.assertEqual(len(txns), 1)
Пример #14
0
 def test_sync_order(self):
     ledger = Ledger(os.path.join('fixtures', 'empty.lgr'))
     sync = OfxSynchronizer(ledger)
     ofx = OfxParser.parse(
         file(os.path.join('fixtures', 'checking_order.ofx')))
     txns = sync.filter(ofx)
     self.assertTrue(txns[0].date < txns[1].date
                     and txns[1].date < txns[2].date)
Пример #15
0
 def test_no_institution(self):
     ofxpath = os.path.join('fixtures', 'no-institution.ofx')
     sync = OfxSynchronizer(self.lgr)
     ofx = OfxSynchronizer.parse_file(ofxpath)
     txns = sync.filter(
         ofx.account.statement.transactions,
         ofx.account.account_id)
     self.assertEqual(len(txns), 3)
Пример #16
0
 def test_sync_order(self):
     ledger = Ledger(os.path.join('fixtures', 'empty.lgr'))
     sync = OfxSynchronizer(ledger)
     ofx = OfxParser.parse(
         open(os.path.join('fixtures', 'checking_order.ofx')))
     txns = sync.filter(ofx.account.statement.transactions,
                        ofx.account.account_id)
     self.assertTrue(txns[0].date < txns[1].date
                     and txns[1].date < txns[2].date)
Пример #17
0
 def test_sync_no_ledger(self):
     acct = Mock()
     acct.download = Mock(
         return_value=open(
             os.path.join(
                 'fixtures',
                 'checking.ofx')))
     sync = OfxSynchronizer(None)
     self.assertEqual(len(sync.get_new_txns(acct, 7, 7)[1]), 3)
Пример #18
0
 def test_partial_sync(self):
     ledger = Ledger(os.path.join('fixtures', 'checking-partial.lgr'))
     sync = OfxSynchronizer(ledger)
     ofx = OfxSynchronizer.parse_file(
         os.path.join('fixtures', 'checking.ofx'))
     txns = sync.filter(
         ofx.account.statement.transactions,
         ofx.account.account_id)
     self.assertEqual(len(txns), 1)
Пример #19
0
 def test_comment_txns(self):
     ledger = Ledger(os.path.join('fixtures', 'empty.lgr'))
     sync = OfxSynchronizer(ledger)
     ofx = OfxSynchronizer.parse_file(
         os.path.join('fixtures', 'comments.ofx'))
     txns = sync.filter(
         ofx.account.statement.transactions,
         ofx.account.account_id)
     self.assertEqual(len(txns), 1)
Пример #20
0
 def test_all_new_txns(self):
     ledger = Ledger(os.path.join('fixtures', 'empty.lgr'))
     acct = Mock()
     acct.download = Mock(
         return_value=open(
             os.path.join(
                 'fixtures',
                 'checking.ofx')))
     sync = OfxSynchronizer(ledger)
     self.assertEqual(len(sync.get_new_txns(acct, 7, 7)[1]), 3)
Пример #21
0
 def test_accented_characters_latin1(self):
     ofxpath = os.path.join('fixtures', 'accented_characters_latin1.ofx')
     ofx = OfxSynchronizer.parse_file(ofxpath)
     sync = OfxSynchronizer(self.lgr)
     txns = sync.filter(ofx.account.statement.transactions,
                        ofx.account.account_id)
     converter = OfxConverter(account=ofx.account, name="Foo")
     self.assertEqual(converter.format_payee(txns[0]),
                      "Virement Interac à: Jean")
     self.assertEqual(len(txns), 1)
Пример #22
0
 def test_sync_order(self):
     ledger = Ledger(os.path.join('fixtures', 'empty.lgr'))
     sync = OfxSynchronizer(ledger)
     ofx = OfxParser.parse(
         open(
             os.path.join(
                 'fixtures',
                 'checking_order.ofx')))
     txns = sync.filter(
         ofx.account.statement.transactions,
         ofx.account.account_id)
     self.assertTrue(txns[0].date < txns[1].date and
                     txns[1].date < txns[2].date)
Пример #23
0
def import_ofx(ledger, args):
    sync = OfxSynchronizer(ledger,
                           hardcodeaccount=args.hardcodeaccount,
                           shortenaccount=args.shortenaccount)
    ofx = OfxSynchronizer.parse_file(args.PATH)

    if args.account != None and len(args.account) != len(ofx.accounts):
        sys.stderr.write(
            "number of account name (--account) does not match the number of accounts in the OFX file\n"
        )
        exit(1)

    account_idx = 0
    for account in ofx.accounts:
        txns = sync.filter(account.statement.transactions, account.account_id)
        try:
            accountname = args.account[account_idx]
        except (IndexError, TypeError):
            accountname = None
        if accountname is None:
            if account.institution is not None:
                accountname = "%s:%s" % (account.institution.organization,
                                         account.account_id)
            elif args.account_format is not None:
                accountname = args.account_format.format(
                    account_id=account.account_id,
                    account_type=account.account_type,
                    routing_number=account.routing_number,
                    branch_id=account.branch_id)
            else:
                accountname = "%s:%s" % (UNKNOWN_BANK_ACCOUNT, account_idx)

        # build SecurityList (including indexing by CUSIP and ticker symbol)
        security_list = SecurityList(ofx)

        converter = make_ofx_converter(
            account=account,
            name=accountname,
            ledger=ledger,
            indent=args.indent,
            fid=args.fid,
            unknownaccount=args.unknownaccount,
            payee_format=args.payee_format,
            hardcodeaccount=args.hardcodeaccount,  #TODO
            shortenaccount=args.shortenaccount,  #TODO
            security_list=security_list)
        print_results(converter, ofx, ledger, txns, args, account_idx)
        account_idx += 1
Пример #24
0
def import_ofx(ledger, args):
    sync = OfxSynchronizer(ledger)
    (ofx, txns) = sync.parse_file(args.PATH)
    accountname = args.account
    if accountname is None:
        if ofx.account.institution is not None:
            accountname = "%s:%s" % (ofx.account.institution.organization,
                                     ofx.account.account_id)
        else:
            raise EmptyInstitutionException("Institution provided by OFX is \
empty and no accountname supplied!")
    converter = OfxConverter(account=ofx.account,
                             name=accountname,
                             ledger=ledger,
                             indent=args.indent,
                             fid=args.fid,
                             unknownaccount=args.unknownaccount)
    print_results(converter, ofx, ledger, txns, args)
Пример #25
0
def sync(ledger, accounts, args):
    sync = OfxSynchronizer(ledger)
    for acct in accounts:
        try:
            (ofx, txns) = sync.get_new_txns(acct,
                                            resync=args.resync,
                                            max_days=args.max)
            if ofx is not None:
                converter = OfxConverter(account=ofx.account,
                                         name=acct.description,
                                         ledger=ledger,
                                         indent=args.indent,
                                         unknownaccount=args.unknownaccount)
                print_results(converter, ofx, ledger, txns, args)
        except KeyboardInterrupt:
            raise
        except:
            sys.stderr.write("Caught exception processing %s" %
                             (acct.description))
            traceback.print_exc(file=sys.stderr)
Пример #26
0
def sync(ledger, accounts, args):
    sync = OfxSynchronizer(ledger, shortenaccount=args.shortenaccount)
    for acct in accounts:
        try:
            (ofx, txns) = sync.get_new_txns(acct, resync=args.resync,
                                            max_days=args.max)
            if ofx is not None:
                converter = make_ofx_converter(account=ofx.account,
                                               name=acct.description,
                                               ledger=ledger,
                                               indent=args.indent,
                                               fid=None,
                                               unknownaccount=args.unknownaccount,
                                               payee_format=args.payee_format,
                                               hardcodeaccount=None,
                                               shortenaccount=args.shortenaccount,
                                               security_list=SecurityList(ofx))
                print_results(converter, ofx, ledger, txns, args)
        except KeyboardInterrupt:
            raise
        except BaseException:
            sys.stderr.write("Caught exception processing %s\n" %
                             (acct.description))
            traceback.print_exc(file=sys.stderr)
Пример #27
0
def import_ofx(ledger, args):
    sync = OfxSynchronizer(ledger,
                           hardcodeaccount=args.hardcodeaccount,
                           shortenaccount=args.shortenaccount)
    (ofx, txns) = sync.parse_file(args.PATH)
    accountname = args.account
    if accountname is None:
        if ofx.account.institution is not None:
            accountname = "%s:%s" % (ofx.account.institution.organization,
                                     ofx.account.account_id)
        else:
            accountname = UNKNOWN_BANK_ACCOUNT

    converter = OfxConverter(ofx=ofx,
                             name=accountname,
                             ledger=ledger,
                             indent=args.indent,
                             fid=args.fid,
                             unknownaccount=args.unknownaccount,
                             payee_format=args.payee_format,
                             hardcodeaccount=args.hardcodeaccount,
                             shortenaccount=args.shortenaccount)

    print_results(converter, ofx, ledger, txns, args)
Пример #28
0
 def test_no_institution_no_accountname(self):
     ofxpath = os.path.join('fixtures', 'no-institution.ofx')
     (ofx, txns) = OfxSynchronizer(self.lgr).parse_file(ofxpath)
     OfxConverter(ofx, name=None)
Пример #29
0
 def test_no_institution(self):
     ofxpath = os.path.join('fixtures', 'no-institution.ofx')
     OfxSynchronizer(self.lgr).parse_file(ofxpath)
Пример #30
0
 def test_apostrophe(self):
     ofxpath = os.path.join('fixtures', 'apostrophe.ofx')
     OfxSynchronizer(self.lgr).parse_file(ofxpath)
Пример #31
0
 def test_no_institution_no_accountname(self):
     ofxpath = os.path.join('fixtures', 'no-institution.ofx')
     ofx = OfxSynchronizer.parse_file(ofxpath)
     OfxConverter(account=ofx.account, name=None)
Пример #32
0
 def test_one_settleDate(self):
     ofxpath = os.path.join('fixtures', 'fidelity-one-dtsettle.ofx')
     OfxSynchronizer(self.lgr).parse_file(ofxpath)
Пример #33
0
def ofx_sync(ledger):
    return OfxSynchronizer(ledger)
Пример #34
0
 def test_partial_sync(self):
     ledger = Ledger(os.path.join('fixtures', 'checking-partial.lgr'))
     sync = OfxSynchronizer(ledger)
     (ofx, txns) = sync.parse_file(os.path.join('fixtures', 'checking.ofx'))
     self.assertEqual(len(txns), 1)
Пример #35
0
 def test_fully_synced(self):
     ledger = Ledger(os.path.join('fixtures', 'checking.lgr'))
     sync = OfxSynchronizer(ledger)
     (ofx, txns) = sync.parse_file(os.path.join('fixtures', 'checking.ofx'))
     self.assertEqual(txns, [])
Пример #36
0
 def test_comment_txns(self):
     ledger = Ledger(os.path.join('fixtures', 'empty.lgr'))
     sync = OfxSynchronizer(ledger)
     (ofx, txns) = sync.parse_file(os.path.join('fixtures', 'comments.ofx'))
     self.assertEqual(len(txns), 1)
Пример #37
0
 def test_sync_no_ledger(self):
     acct = Mock()
     acct.download = Mock(
         return_value=file(os.path.join('fixtures', 'checking.ofx')))
     sync = OfxSynchronizer(None)
     self.assertEqual(len(sync.get_new_txns(acct, 7, 7)[1]), 3)