module.py 4.9 KB
Newer Older
1 2
# -*- coding: utf-8 -*-

3
# Copyright(C) 2012-2013 Romain Bignon
4
#
5
# This file is part of a weboob module.
6
#
7
# This weboob module is free software: you can redistribute it and/or modify
8 9 10 11
# 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.
#
12
# This weboob module is distributed in the hope that it will be useful,
13 14 15 16 17
# 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
18
# along with this weboob module. If not, see <http://www.gnu.org/licenses/>.
19

20
from collections import OrderedDict
21
from functools import reduce
22

23
from weboob.capabilities.bank import CapBankWealth, AccountNotFound
24
from weboob.capabilities.contact import CapContact
25
from weboob.capabilities.profile import CapProfile
26
from weboob.tools.backend import Module, BackendConfig
27 28 29 30 31
from weboob.tools.value import ValueBackendPassword, Value

from .browser import BanquePopulaire


Florent Fourcot's avatar
Florent Fourcot committed
32
__all__ = ['BanquePopulaireModule']
33 34


35
class BanquePopulaireModule(Module, CapBankWealth, CapContact, CapProfile):
36
    NAME = 'banquepopulaire'
37
    MAINTAINER = u'Romain Bignon'
38
    EMAIL = 'romain@weboob.org'
Romain Bignon's avatar
Romain Bignon committed
39
    VERSION = '1.5'
40
    DESCRIPTION = u'Banque Populaire'
41 42 43
    LICENSE = 'AGPLv3+'
    website_choices = OrderedDict([(k, u'%s (%s)' % (v, k)) for k, v in sorted({
        'www.ibps.alpes.banquepopulaire.fr': u'Alpes',
44
        'www.ibps.alsace.banquepopulaire.fr': u'Alsace Lorraine Champagne',
45
        'www.ibps.bpalc.banquepopulaire.fr' : u'Alsace Lorraine Champagne',
46
        'www.ibps.bpaca.banquepopulaire.fr': u'Aquitaine Centre atlantique',
47
        'www.ibps.atlantique.banquepopulaire.fr': u'Atlantique',
48
        'www.ibps.bpgo.banquepopulaire.fr': u'Grand Ouest',
49
        'www.ibps.loirelyonnais.banquepopulaire.fr': u'Auvergne Rhône Alpes',
50
        'www.ibps.bpaura.banquepopulaire.fr': u'Auvergne Rhône Alpes',
51
        'www.ibps.banquedesavoie.banquepopulaire.fr': u'Banque de Savoie',
52
        'www.ibps.bpbfc.banquepopulaire.fr': u'Bourgogne Franche-Comté',
53 54 55
        'www.ibps.bretagnenormandie.cmm.groupe.banquepopulaire.fr': u'Crédit Maritime Bretagne Normandie',
        'www.ibps.atlantique.creditmaritime.groupe.banquepopulaire.fr': u'Crédit Maritime Atlantique',
        'www.ibps.sudouest.creditmaritime.groupe.banquepopulaire.fr': u'Crédit Maritime du Littoral du Sud-Ouest',
56 57
        'www.ibps.lorrainechampagne.banquepopulaire.fr': u'Lorraine Champagne',
        'www.ibps.massifcentral.banquepopulaire.fr': u'Massif central',
58
        'www.ibps.mediterranee.banquepopulaire.fr': u'Méditerranée',
59 60 61 62 63 64
        'www.ibps.nord.banquepopulaire.fr': u'Nord',
        'www.ibps.occitane.banquepopulaire.fr': u'Occitane',
        'www.ibps.ouest.banquepopulaire.fr': u'Ouest',
        'www.ibps.rivesparis.banquepopulaire.fr': u'Rives de Paris',
        'www.ibps.sud.banquepopulaire.fr': u'Sud',
        'www.ibps.valdefrance.banquepopulaire.fr': u'Val de France',
65
        }.items(), key=lambda k_v: (k_v[1], k_v[0]))])
66 67 68
    CONFIG = BackendConfig(Value('website',  label=u'Région', choices=website_choices),
                           ValueBackendPassword('login',    label='Identifiant', masked=False),
                           ValueBackendPassword('password', label='Mot de passee'))
69 70 71
    BROWSER = BanquePopulaire

    def create_default_browser(self):
72 73 74 75
        repls = [
            ('alsace', 'bpalc'),
            ('lorrainechampagne', 'bpalc'),
            ('loirelyonnais', 'bpaura'),
76 77
            ('alpes', 'bpaura'),
            ('massifcentral', 'bpaura'),
78 79 80
            ('atlantique.creditmaritime', 'cmgo.creditmaritime'),
            ('bretagnenormandie.cmm', 'cmgo'),
            ('atlantique.banquepopulaire', 'bpgo.banquepopulaire'),
81
            ('ouest.banquepopulaire', 'bpgo.banquepopulaire'),
82
        ]
83 84
        website = reduce(lambda a, kv: a.replace(*kv), repls, self.config['website'].get())
        return self.create_browser(website,
85
                                   self.config['login'].get(),
86 87
                                   self.config['password'].get(),
                                   weboob=self.weboob)
88 89

    def iter_accounts(self):
90
        return self.browser.get_accounts_list()
91 92

    def get_account(self, _id):
93
        account = self.browser.get_account(_id)
94 95 96 97 98 99
        if account:
            return account
        else:
            raise AccountNotFound()

    def iter_history(self, account):
100
        return self.browser.get_history(account)
Romain Bignon's avatar
Romain Bignon committed
101 102

    def iter_coming(self, account):
103
        return self.browser.get_history(account, coming=True)
104 105

    def iter_investment(self, account):
106
        return self.browser.get_investment(account)
107 108 109

    def iter_contacts(self):
        return self.browser.get_advisor()
110 111 112

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