Exemplo n.º 1
0
class BforbankModule(Module, CapBankWealth):
    NAME = 'bforbank'
    DESCRIPTION = u'BforBank'
    MAINTAINER = u'Baptiste Delpey'
    EMAIL = '*****@*****.**'
    LICENSE = 'LGPLv3+'
    VERSION = '1.6'
    CONFIG = BackendConfig(ValueBackendPassword('login',    label='Identifiant', masked=False),
                           ValueBackendPassword('password', label='Code personnel', regexp=r'\d+$'),
                           ValueDate('birthdate', label='Date de naissance', formats=('%d/%m/%Y',))
                           )

    BROWSER = BforbankBrowser

    def create_default_browser(self):
        return self.create_browser(self.config['birthdate'].get(),
                                   self.config['login'].get(),
                                   self.config['password'].get(),
                                   weboob=self.weboob)

    def get_account(self, _id):
        return find_object(self.browser.iter_accounts(), id=_id, error=AccountNotFound)

    def iter_accounts(self):
        return self.browser.iter_accounts()

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

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

    def iter_investment(self, account):
        return self.browser.iter_investment(account)
Exemplo n.º 2
0
class INGModule(Module, CapBankTransfer, CapDocument, CapProfile):
    NAME = 'ing'
    MAINTAINER = u'Florent Fourcot'
    EMAIL = '*****@*****.**'
    VERSION = '1.3'
    LICENSE = 'AGPLv3+'
    DESCRIPTION = 'ING Direct'
    CONFIG = BackendConfig(
        ValueBackendPassword('login', label=u'Numéro client', masked=False),
        ValueBackendPassword('password',
                             label='Code secret',
                             regexp='^(\d{6}|)$'),
        ValueDate('birthday',
                  label='Date de naissance',
                  formats=('%d%m%Y', '%d/%m/%Y', '%d-%m-%Y')))
    BROWSER = IngBrowser

    def create_default_browser(self):
        return self.create_browser(self.config['login'].get(),
                                   self.config['password'].get(),
                                   birthday=self.config['birthday'].get())

    def iter_resources(self, objs, split_path):
        if Account in objs:
            self._restrict_level(split_path)
            return self.iter_accounts()
        if Subscription in objs:
            self._restrict_level(split_path)
            return self.iter_subscription()

    def iter_accounts(self):
        return self.browser.get_accounts_list()

    def get_account(self, _id):
        return self.browser.get_account(_id)

    def iter_history(self, account):
        if not isinstance(account, Account):
            account = self.get_account(account)
        return self.browser.get_history(account)

    def iter_transfer_recipients(self, account):
        if not isinstance(account, Account):
            account = self.get_account(account)
        return self.browser.iter_recipients(account)

    def init_transfer(self, transfer, **params):
        self.logger.info('Going to do a new transfer')
        transfer.label = ' '.join(
            w for w in re.sub('[^0-9a-zA-Z/\-\?:\(\)\.,\'\+ ]+', '',
                              transfer.label).split()).upper()
        if transfer.account_iban:
            account = find_object(self.iter_accounts(),
                                  iban=transfer.account_iban,
                                  error=AccountNotFound)
        else:
            account = find_object(self.iter_accounts(),
                                  id=transfer.account_id,
                                  error=AccountNotFound)

        if transfer.recipient_iban:
            recipient = find_object(self.iter_transfer_recipients(account.id),
                                    iban=transfer.recipient_iban,
                                    error=RecipientNotFound)
        else:
            recipient = find_object(self.iter_transfer_recipients(account.id),
                                    id=transfer.recipient_id,
                                    error=RecipientNotFound)

        return self.browser.init_transfer(account, recipient, transfer)

    def execute_transfer(self, transfer, **params):
        return self.browser.execute_transfer(transfer)

    def transfer_check_exec_date(self, old_exec_date, new_exec_date):
        return old_exec_date <= new_exec_date <= old_exec_date + timedelta(
            days=4)

    def iter_investment(self, account):
        if not isinstance(account, Account):
            account = self.get_account(account)
        return self.browser.get_investments(account)

    def iter_coming(self, account):
        if not isinstance(account, Account):
            account = self.get_account(account)
        return self.browser.get_coming(account)

    def iter_subscription(self):
        return self.browser.get_subscriptions()

    def get_subscription(self, _id):
        return find_object(self.browser.get_subscriptions(),
                           id=_id,
                           error=SubscriptionNotFound)

    def get_document(self, _id):
        subscription = self.get_subscription(_id.split('-')[0])
        return find_object(self.browser.get_documents(subscription),
                           id=_id,
                           error=DocumentNotFound)

    def iter_documents(self, subscription):
        if not isinstance(subscription, Subscription):
            subscription = self.get_subscription(subscription)
        return self.browser.get_documents(subscription)

    def download_document(self, bill):
        if not isinstance(bill, Bill):
            bill = self.get_document(bill)
        self.get_document(bill.id)
        try:
            self.browser.predownload(bill)
        except ServerError:
            return NotAvailable
        assert (self.browser.response.headers['content-type']
                in ["application/pdf", "application/download"])
        return self.browser.response.content

    def get_profile(self):
        return self.browser.get_profile()
Exemplo n.º 3
0
class INGModule(Module, CapBankWealth, CapBankTransfer, CapDocument,
                CapProfile):
    NAME = 'ing'
    MAINTAINER = 'Florent Fourcot'
    EMAIL = '*****@*****.**'
    VERSION = '1.6'
    LICENSE = 'LGPLv3+'
    DESCRIPTION = 'ING France'
    CONFIG = BackendConfig(
        ValueBackendPassword('login',
                             label='Numéro client',
                             masked=False,
                             regexp='^(\d{1,10})$'),
        ValueBackendPassword('password',
                             label='Code secret',
                             regexp='^(\d{6})$'),
        ValueDate('birthday',
                  label='Date de naissance',
                  formats=('%d%m%Y', '%d/%m/%Y', '%d-%m-%Y')))
    BROWSER = IngAPIBrowser

    accepted_document_types = (DocumentTypes.STATEMENT, )

    def create_default_browser(self):
        return self.create_browser(self.config['login'].get(),
                                   self.config['password'].get(),
                                   birthday=self.config['birthday'].get())

    def iter_resources(self, objs, split_path):
        if Account in objs:
            self._restrict_level(split_path)
            return self.iter_accounts()
        if Subscription in objs:
            self._restrict_level(split_path)
            return self.iter_subscription()

    ############# CapBank #############
    def iter_accounts(self):
        return self.browser.iter_matching_accounts()

    def get_account(self, _id):
        return find_object(self.iter_accounts(), id=_id, error=AccountNotFound)

    def iter_history(self, account):
        if not isinstance(account, Account):
            account = self.get_account(account)
        return self.browser.iter_history(account)

    def iter_coming(self, account):
        if not isinstance(account, Account):
            account = self.get_account(account)
        return self.browser.iter_coming(account)

    ############# CapWealth #############
    def iter_investment(self, account):
        if not isinstance(account, Account):
            account = self.get_account(account)
        return self.browser.get_investments(account)

    ############# CapTransfer #############
    def iter_transfer_recipients(self, account):
        if not isinstance(account, Account):
            account = self.get_account(account)
        return self.browser.iter_recipients(account)

    def init_transfer(self, transfer, **params):
        self.logger.info('Going to do a new transfer')

        account = strict_find_object(self.iter_accounts(),
                                     id=transfer.account_id,
                                     error=AccountNotFound)

        recipient = strict_find_object(self.iter_transfer_recipients(account),
                                       id=transfer.recipient_id,
                                       error=RecipientNotFound)

        transfer.amount = Decimal(transfer.amount).quantize(Decimal('.01'))

        return self.browser.init_transfer(account, recipient, transfer)

    def execute_transfer(self, transfer, **params):
        return self.browser.execute_transfer(transfer)

    ############# CapDocument #############
    def iter_subscription(self):
        return self.browser.get_subscriptions()

    def get_subscription(self, _id):
        return find_object(self.browser.get_subscriptions(),
                           id=_id,
                           error=SubscriptionNotFound)

    def get_document(self, _id):
        subscription = self.get_subscription(_id.split('-')[0])
        return find_object(self.browser.get_documents(subscription),
                           id=_id,
                           error=DocumentNotFound)

    def iter_documents(self, subscription):
        if not isinstance(subscription, Subscription):
            subscription = self.get_subscription(subscription)
        return self.browser.get_documents(subscription)

    def download_document(self, bill):
        if not isinstance(bill, Bill):
            bill = self.get_document(bill)

        return self.browser.download_document(bill).content

    ############# CapProfile #############
    def get_profile(self):
        return self.browser.get_profile()