module.py 3.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
# -*- coding: utf-8 -*-

# Copyright(C) 2018      Vincent A
#
# 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 __future__ import unicode_literals


from weboob.tools.backend import Module, BackendConfig
from weboob.tools.value import ValueBackendPassword
25
from weboob.capabilities.bank import CapBankWealth, Account
26 27 28 29 30 31 32 33 34 35 36 37
from weboob.capabilities.base import find_object
from weboob.capabilities.bill import (
    CapDocument, Subscription, SubscriptionNotFound, DocumentNotFound, Document,
)
from weboob.capabilities.profile import CapProfile

from .browser import BoldenBrowser


__all__ = ['BoldenModule']


38
class BoldenModule(Module, CapBankWealth, CapDocument, CapProfile):
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
    NAME = 'bolden'
    DESCRIPTION = 'Bolden'
    MAINTAINER = 'Vincent A'
    EMAIL = 'dev@indigo.re'
    LICENSE = 'AGPLv3+'
    VERSION = '1.4'

    BROWSER = BoldenBrowser

    CONFIG = BackendConfig(
        ValueBackendPassword('login', label='Email', masked=False),
        ValueBackendPassword('password', label='Mot de passe'),
    )

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

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

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

62 63 64
    def iter_investment(self, account):
        return self.browser.iter_investments()

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
    def get_profile(self):
        return self.browser.get_profile()

    def iter_subscription(self):
        sub = Subscription()
        sub.id = '_bolden_'
        sub.subscriber = self.get_profile().name
        sub.label = 'Bolden %s' % sub.subscriber
        return [sub]

    def get_subscription(self, _id):
        if _id == '_bolden_':
            return self.iter_subscription()[0]
        raise SubscriptionNotFound()

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

    def get_document(self, id):
        return find_object(self.browser.iter_documents(), id=id, error=DocumentNotFound)

    def download_document(self, doc):
        if not isinstance(doc, Document):
            doc = self.get_document(doc)
        return self.browser.open(doc.url).content

    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()