<commit_before># -*- coding: utf-8 -*-

# Copyright(C) 2009-2010  <NAME>, <NAME>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

from __future__ import with_statement

import logging

import weboob
from weboob.capabilities.bank import ICapBank
from weboob.tools.application.repl import ReplApplication


__all__ = ['Boobank']


class Boobank(ReplApplication):
    APPNAME = 'boobank'
    VERSION = '0.2'
    COPYRIGHT = 'Copyright(C) 2010 <NAME>, <NAME>'
    CAPS = ICapBank

    def do_list(self, line):
        """
        list

        List every available accounts.
        """
        tot_balance = 0.0
        tot_coming = 0.0
        try:
            for backend, account in self.do('iter_accounts'):
                self.format(account)
                tot_balance += account.balance
                tot_coming += account.coming
        except weboob.core.CallErrors, errors:
            for backend, error, backtrace in errors:
                if isinstance(error, weboob.tools.browser.BrowserIncorrectPassword):
                    logging.error(u'Error: Incorrect password for backend %s' % backend.name)
                else:
                    logging.error(u'Error[%s]: %s\n%s' % (backend.name, error, backtrace))
        else:
            self.format((('label', 'Total'),
                         ('balance', tot_balance),
                         ('coming', tot_coming)))

    def do_history(self, id):
        """
        history ID

        Display old operations.
        """
        id, backend_name = self.parse_id(id)
        names = (backend_name,) if backend_name is not None else None
        self.load_backends(ICapBank, names=names)

        def do(backend):
            account = backend.get_account(id)
            return backend.iter_history(account)

        for backend, operation in self.do(do):
            self.format(operation)

    def do_coming(self, id):
        """
        coming ID

        Display all future operations.
        """
        id, backend_name = self.parse_id(id)
        names = (backend_name,) if backend_name is not None else None
        self.load_backends(ICapBank, names=names)

        def do(backend):
            account = backend.get_account(id)
            return backend.iter_operations(account)

        for backend, operation in self.do(do):
            self.format(operation)

    def do_transfer(self, line):
        """
        transfer FROM TO AMOUNT

        Make a transfer beetwen two account
        """
        id_from, id_to, amount = self.parseargs(line, 3, 3)

        id_from, backend_name = self.parse_id(id_from)
        id_to, backend_name = self.parse_id(id_to)
        names = (backend_name,) if backend_name is not None else None
        self.load_backends(ICapBank, names=names)

        def do(backend):
            return backend.transfer(id_from, id_to, float(amount))<commit_msg>store listed accounts and completion on 'coming', 'history' and 'transfer' commands<commit_after># -*- coding: utf-8 -*-

# Copyright(C) 2009-2010  <NAME>, <NAME>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

from __future__ import with_statement

import logging

import weboob
from weboob.capabilities.bank import ICapBank
from weboob.tools.application.repl import ReplApplication


__all__ = ['Boobank']


class Boobank(ReplApplication):
    APPNAME = 'boobank'
    VERSION = '0.2'
    COPYRIGHT = 'Copyright(C) 2010 <NAME>, <NAME>'
    CAPS = ICapBank

    accounts = []

    def do_list(self, line):
        """
        list

        List every available accounts.
        """
        tot_balance = 0.0
        tot_coming = 0.0
        self.accounts = []
        try:
            for backend, account in self.do('iter_accounts'):
                self.format(account)
                tot_balance += account.balance
                tot_coming += account.coming
                self.accounts.append(account)
        except weboob.core.CallErrors, errors:
            for backend, error, backtrace in errors:
                if isinstance(error, weboob.tools.browser.BrowserIncorrectPassword):
                    logging.error(u'Error: Incorrect password for backend %s' % backend.name)
                else:
                    logging.error(u'Error[%s]: %s\n%s' % (backend.name, error, backtrace))
        else:
            self.format((('label', 'Total'),
                         ('balance', tot_balance),
                         ('coming', tot_coming)))

    def _complete_account(self, exclude=None):
        if exclude:
            id, backend = self.parse_id(exclude)
        return ['%s@%s' % (acc.id, acc.backend) for acc in self.accounts if not exclude or (acc.id != id and acc.backend == backend)]

    def complete_history(self, text, line, *ignored):
        args = line.split(' ')
        if len(args) == 2:
            return self._complete_account()

    def do_history(self, id):
        """
        history ID

        Display old operations.
        """
        id, backend_name = self.parse_id(id)
        names = (backend_name,) if backend_name is not None else None
        self.load_backends(ICapBank, names=names)

        def do(backend):
            account = backend.get_account(id)
            return backend.iter_history(account)

        for backend, operation in self.do(do):
            self.format(operation)

    def complete_coming(self, text, line, *ignored):
        args = line.split(' ')
        if len(args) == 2:
            return self._complete_account()

    def do_coming(self, id):
        """
        coming ID

        Display all future operations.
        """
        id, backend_name = self.parse_id(id)
        names = (backend_name,) if backend_name is not None else None
        self.load_backends(ICapBank, names=names)

        def do(backend):
            account = backend.get_account(id)
            return backend.iter_operations(account)

        for backend, operation in self.do(do):
            self.format(operation)

    def complete_transfer(self, text, line, *ignored):
        args = line.split(' ')
        if len(args) == 2:
            return self._complete_account()
        if len(args) == 3:
            return self._complete_account(args[1])

    def do_transfer(self, line):
        """
        transfer FROM TO AMOUNT

        Make a transfer beetwen two account
        """
        id_from, id_to, amount = self.parseargs(line, 3, 3)

        id_from, backend_name = self.parse_id(id_from)
        id_to, backend_name = self.parse_id(id_to)
        names = (backend_name,) if backend_name is not None else None
        self.load_backends(ICapBank, names=names)

        def do(backend):
            return backend.transfer(id_from, id_to, float(amount))
{'fraction_non_alphanumeric': 0.09535822401614531, 'fraction_numerical': 0.009712411705348133, 'mean_word_length': 2.3023740108288213, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7574647', 'n_tokens_mistral': 2301, 'n_tokens_neox': 2174, 'n_words': 696}