browser.py 2.27 KB
Newer Older
1 2 3 4
# -*- coding: utf-8 -*-

# Copyright(C) 2016      Bezleputh
#
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 21 22 23 24 25 26 27 28 29


from weboob.browser import LoginBrowser, need_login, URL
from weboob.exceptions import BrowserIncorrectPassword
from weboob.tools.date import LinearDateGuesser
from weboob.capabilities.bank import Account
from .pages import LoginPage, HomePage, AvoirPage, HistoryPage


class CreditdunordpeeBrowser(LoginBrowser):
    BASEURL = 'https://salaries.pee.credit-du-nord.fr'
30
    home = URL('/?/portal/fr/salarie-cdn/', HomePage)
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
    login = URL('/portal/login', LoginPage)
    avoir = URL(u'/portal/salarie-cdn/monepargne/mesavoirs', AvoirPage)
    history = URL(u'/portal/salarie-cdn/operations/consulteroperations\?scenario=ConsulterOperationsEffectuees',
                  HistoryPage)

    def do_login(self):
        self.home.stay_or_go()
        passwd = self.page.get_coded_passwd(self.password)
        d = {'initialURI': "/portal/fr/salarie-cdn/",
             'password': passwd,
             'username': self.username}

        self.login.go(data=d)

        if not (self.home.is_here() and self.page.is_logged()):
            raise BrowserIncorrectPassword()

    @need_login
    def iter_accounts(self):
        account = Account(self.username)
51
        return iter([self.avoir.go().get_account(obj=account)])
52 53 54 55

    @need_login
    def get_history(self):
        transactions = list(self.history.go().get_history(date_guesser=LinearDateGuesser()))
56
        transactions.sort(key=lambda tr: tr.date, reverse=True)
57 58 59 60 61
        return transactions

    @need_login
    def iter_investment(self):
        return self.avoir.go().iter_investment()