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

# Copyright(C) 2010-2013 <NAME>
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.


from decimal import Decimal
from datetime import datetime, timedelta

from weboob.capabilities.bank import CapBank, AccountNotFound, Account, Recipient
from weboob.capabilities.messages import CapMessages, Thread
from weboob.tools.backend import Module, BackendConfig
from weboob.tools.value import ValueBackendPassword, Value

from .deprecated.browser import BNPorc
from .enterprise.browser import BNPEnterprise
from .company.browser import BNPCompany
from .pp.browser import BNPParibasBrowser


__all__ = ['BNPorcModule']


class BNPorcModule(Module, CapBank, CapMessages):
    NAME = 'bnporc'
    MAINTAINER = u'<NAME>'
    EMAIL = '<EMAIL>'
    VERSION = '1.1'
    LICENSE = 'AGPLv3+'
    DESCRIPTION = 'BNP Paribas'
    CONFIG = BackendConfig(
        ValueBackendPassword('login',      label=u'Numéro client', masked=False),
        ValueBackendPassword('password',   label=u'Code secret', regexp='^(\d{6}|)$'),
        #ValueBackendPassword('<PASSWORD>', default='',
        #    label='Password to set when the allowed uses are exhausted (6 digits)',
        #    regexp='^(\d{6}|)$'),
        Value('website', label='Type de compte', default='pp',
              choices={'pp': 'Particuliers/Professionnels',
                       'ent': 'Entreprises',
                       'ppold': 'Particuliers/Professionnels (ancien site)',
                       'ent2': 'Entreprises et PME (nouveau site)'}))
    STORAGE = {'seen': []}

    # Store the messages *list* for this duration
    CACHE_THREADS = timedelta(seconds=3 * 60 * 60)

    def __init__(self, *args, **kwargs):
        Module.__init__(self, *args, **kwargs)
        self._threads = None
        self._threads_age = datetime.utcnow()

    def create_default_browser(self):
        b = {'ppold': BNPorc, 'ent': BNPEnterprise, 'ent2': BNPCompany, 'pp': BNPParibasBrowser}
        self.BROWSER = b[self.config['website'].get()]
        return self.create_browser(self.config['login'].get(),
                                   self.config['password'].get())

    def iter_accounts(self):
        for account in self.browser.get_accounts_list():
            yield account

    def get_account(self, _id):
        if not _id.isdigit():
            raise AccountNotFound()
        with self.browser:
            account = self.browser.get_account(_id)
        if account:
            return account
        else:
            raise AccountNotFound()

    def iter_history(self, account):
        with self.browser:
            return self.browser.iter_history(account)

    def iter_coming(self, account):
        with self.browser:
            return self.browser.iter_coming_operations(account)

    def iter_investment(self, account):
        with self.browser:
            return self.browser.iter_investment(account)

    def iter_transfer_recipients(self, ignored):
        if self.config['website'].get() != 'pp':
            raise NotImplementedError()

        for account in self.browser.get_transfer_accounts().itervalues():
            recipient = Recipient()
            recipient.id = account.id
            recipient.label = account.label
            yield recipient

    def transfer(self, account, to, amount, reason=None):
        if self.config['website'].get() != 'pp':
            raise NotImplementedError()

        if isinstance(account, Account):
            account = account.id

        try:
            assert account.isdigit()<commit_msg>bnporc adapt module to use Browser2<commit_after># -*- coding: utf-8 -*-

# Copyright(C) 2010-2013 <NAME>
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.


from decimal import Decimal
from datetime import datetime, timedelta

from weboob.capabilities.bank import CapBank, AccountNotFound, Account, Recipient
from weboob.capabilities.messages import CapMessages, Thread
from weboob.tools.backend import Module, BackendConfig
from weboob.tools.value import ValueBackendPassword, Value

from .deprecated.browser import BNPorc
from .enterprise.browser import BNPEnterprise
from .company.browser import BNPCompany
from .pp.browser import BNPParibasBrowser


__all__ = ['BNPorcModule']


class BNPorcModule(Module, CapBank, CapMessages):
    NAME = 'bnporc'
    MAINTAINER = u'<NAME>'
    EMAIL = '<EMAIL>'
    VERSION = '1.1'
    LICENSE = 'AGPLv3+'
    DESCRIPTION = 'BNP Paribas'
    CONFIG = BackendConfig(
        ValueBackendPassword('login',      label=u'Numéro client', masked=False),
        ValueBackendPassword('password',   label=u'Code secret', regexp='^(\d{6}|)$'),
        #ValueBackendPassword('<PASSWORD>', default='',
        #    label='Password to set when the allowed uses are exhausted (6 digits)',
        #    regexp='^(\d{6}|)$'),
        Value('website', label='Type de compte', default='pp',
              choices={'pp': 'Particuliers/Professionnels',
                       'ent': 'Entreprises',
                       'ppold': 'Particuliers/Professionnels (ancien site)',
                       'ent2': 'Entreprises et PME (nouveau site)'}))
    STORAGE = {'seen': []}

    # Store the messages *list* for this duration
    CACHE_THREADS = timedelta(seconds=3 * 60 * 60)

    def __init__(self, *args, **kwargs):
        Module.__init__(self, *args, **kwargs)
        self._threads = None
        self._threads_age = datetime.utcnow()

    def create_default_browser(self):
        b = {'ppold': BNPorc, 'ent': BNPEnterprise, 'ent2': BNPCompany, 'pp': BNPParibasBrowser}
        self.BROWSER = b[self.config['website'].get()]
        return self.create_browser(self.config['login'].get(),
                                   self.config['password'].get())

    def iter_accounts(self):
        for account in self.browser.get_accounts_list():
            yield account

    def get_account(self, _id):
        if not _id.isdigit():
            raise AccountNotFound()
        account = self.browser.get_account(_id)
        if account:
            return account
        else:
            raise AccountNotFound()

    def iter_history(self, account):
        return self.browser.iter_history(account)

    def iter_coming(self, account):
        return self.browser.iter_coming_operations(account)

    def iter_investment(self, account):
        return self.browser.iter_investment(account)

    def iter_transfer_recipients(self, ignored):
        if self.config['website'].get() != 'pp':
            raise NotImplementedError()

        for account in self.browser.get_transfer_accounts().itervalues():
            recipient = Recipient()
            recipient.id = account.id
            recipient.label = account.label
            yield recipient

    def transfer(self, account, to, amount, reason=None):
        if self.config['website'].get() != 'pp':
            raise NotImplementedError()

        if isinstance(account, Account):
            account = account.id

        try:
            assert account.isdigit()
{'fraction_non_alphanumeric': 0.1075242718446602, 'fraction_numerical': 0.005703883495145631, 'mean_word_length': 2.869014084507042, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1427049', 'n_tokens_mistral': 2380, 'n_tokens_neox': 2296, 'n_words': 690}