add module banquepopulaire (closes #835)
This commit is contained in:
parent
c9cbba9076
commit
d4df7c6277
6 changed files with 359 additions and 0 deletions
23
modules/banquepopulaire/__init__.py
Normal file
23
modules/banquepopulaire/__init__.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2012 Romain Bignon
|
||||
#
|
||||
# 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 .backend import BanquePopulaireBackend
|
||||
|
||||
__all__ = ['BanquePopulaireBackend']
|
||||
82
modules/banquepopulaire/backend.py
Normal file
82
modules/banquepopulaire/backend.py
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2012 Romain Bignon
|
||||
#
|
||||
# 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 weboob.capabilities.bank import ICapBank, AccountNotFound
|
||||
from weboob.tools.backend import BaseBackend, BackendConfig
|
||||
from weboob.tools.ordereddict import OrderedDict
|
||||
from weboob.tools.value import ValueBackendPassword, Value
|
||||
|
||||
from .browser import BanquePopulaire
|
||||
|
||||
|
||||
__all__ = ['BanquePopulaireBackend']
|
||||
|
||||
|
||||
class BanquePopulaireBackend(BaseBackend, ICapBank):
|
||||
NAME = 'banquepopulaire'
|
||||
MAINTAINER = 'Romain Bignon'
|
||||
EMAIL = 'romain@weboob.org'
|
||||
VERSION = '0.d'
|
||||
DESCRIPTION = u'Banque Populaire French bank website'
|
||||
LICENSE = 'AGPLv3+'
|
||||
website_choices = OrderedDict([(k, u'%s (%s)' % (v, k)) for k, v in sorted({
|
||||
'www.ibps.alpes.banquepopulaire.fr': u'Alpes',
|
||||
'www.ibps.alsace.banquepopulaire.fr': u'Alsace',
|
||||
'www.bpaca.banquepopulaire.fr': u'Aquitaine Centre atlantique',
|
||||
'www.ibps.atlantique.banquepopulaire.fr': u'Atlantique',
|
||||
'www.ibps.bpbfc.banquepopulaire.fr': u'Bourgogne-Franche Comté',
|
||||
'www.ibps.cotedazur.banquepopulaire.fr': u'Côte d\'azur',
|
||||
'www.ibps.loirelyonnais.banquepopulaire.fr': u'Loire et Lyonnais',
|
||||
'www.ibps.lorrainechampagne.banquepopulaire.fr': u'Lorraine Champagne',
|
||||
'www.ibps.massifcentral.banquepopulaire.fr': u'Massif central',
|
||||
'www.ibps.nord.banquepopulaire.fr': u'Nord',
|
||||
'www.ibps.occitane.banquepopulaire.fr': u'Occitane',
|
||||
'www.ibps.ouest.banquepopulaire.fr': u'Ouest',
|
||||
'www.ibps.provencecorse.banquepopulaire.fr': u'Provence et Corse',
|
||||
'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',
|
||||
}.iteritems())])
|
||||
CONFIG = BackendConfig(Value('website', label='Website to use', choices=website_choices),
|
||||
ValueBackendPassword('login', label='Account ID', masked=False),
|
||||
ValueBackendPassword('password', label='Password'))
|
||||
BROWSER = BanquePopulaire
|
||||
|
||||
def create_default_browser(self):
|
||||
return self.create_browser(self.config['website'].get(),
|
||||
self.config['login'].get(),
|
||||
self.config['password'].get())
|
||||
|
||||
def iter_accounts(self):
|
||||
with self.browser:
|
||||
return self.browser.get_accounts_list()
|
||||
|
||||
def get_account(self, _id):
|
||||
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.get_history(account)
|
||||
98
modules/banquepopulaire/browser.py
Normal file
98
modules/banquepopulaire/browser.py
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2012 Romain Bignon
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
|
||||
import urllib
|
||||
|
||||
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
|
||||
|
||||
from .pages import LoginPage, IndexPage, AccountsPage, TransactionsPage
|
||||
|
||||
|
||||
__all__ = ['BanquePopulaire']
|
||||
|
||||
|
||||
class BanquePopulaire(BaseBrowser):
|
||||
PROTOCOL = 'https'
|
||||
ENCODING = 'iso-8859-15'
|
||||
PAGES = {'https://[^/]+/auth/UI/Login.*': LoginPage,
|
||||
'https://[^/]+/cyber/internet/Login.do': IndexPage,
|
||||
'https://[^/]+/cyber/internet/StartTask.do\?taskInfoOID=mesComptes.*': AccountsPage,
|
||||
'https://[^/]+/cyber/internet/ContinueTask.do\?.*dialogActionPerformed=SOLDE.*': TransactionsPage,
|
||||
'https://[^/]+/cyber/internet/Page.do\?.*taskInfoOID=mesComptes.*': TransactionsPage,
|
||||
}
|
||||
|
||||
def __init__(self, website, *args, **kwargs):
|
||||
self.DOMAIN = website
|
||||
self.token = None
|
||||
|
||||
BaseBrowser.__init__(self, *args, **kwargs)
|
||||
|
||||
def is_logged(self):
|
||||
return self.page and not self.is_on_page(LoginPage)
|
||||
|
||||
def login(self):
|
||||
"""
|
||||
Attempt to log in.
|
||||
Note: this method does nothing if we are already logged in.
|
||||
"""
|
||||
assert isinstance(self.username, basestring)
|
||||
assert isinstance(self.password, basestring)
|
||||
|
||||
if self.is_logged():
|
||||
return
|
||||
|
||||
if not self.is_on_page(LoginPage):
|
||||
self.home()
|
||||
|
||||
self.page.login(self.username, self.password)
|
||||
|
||||
if not self.is_logged():
|
||||
raise BrowserIncorrectPassword()
|
||||
|
||||
self.token = self.page.get_token()
|
||||
|
||||
def get_accounts_list(self):
|
||||
self.location(self.buildurl('/cyber/internet/StartTask.do', taskInfoOID='mesComptes', token=self.token))
|
||||
return self.page.get_list()
|
||||
|
||||
def get_account(self, id):
|
||||
assert isinstance(id, basestring)
|
||||
|
||||
l = self.get_accounts_list()
|
||||
for a in l:
|
||||
if a.id == id:
|
||||
return a
|
||||
|
||||
return None
|
||||
|
||||
def get_history(self, account):
|
||||
self.location('/cyber/internet/ContinueTask.do', urllib.urlencode(account._params))
|
||||
|
||||
while 1:
|
||||
assert self.is_on_page(TransactionsPage)
|
||||
|
||||
for tr in self.page.get_history():
|
||||
yield tr
|
||||
|
||||
next_params = self.page.get_next_params()
|
||||
if next_params is None:
|
||||
return
|
||||
|
||||
self.location(self.buildurl('/cyber/internet/Page.do', **next_params))
|
||||
BIN
modules/banquepopulaire/favicon.png
Normal file
BIN
modules/banquepopulaire/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
126
modules/banquepopulaire/pages.py
Normal file
126
modules/banquepopulaire/pages.py
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2012 Romain Bignon
|
||||
#
|
||||
# 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 urlparse import urlsplit, parse_qsl
|
||||
from decimal import Decimal
|
||||
import re
|
||||
|
||||
from weboob.tools.browser import BasePage
|
||||
from weboob.capabilities.bank import Account
|
||||
from weboob.tools.capabilities.bank.transactions import FrenchTransaction
|
||||
|
||||
|
||||
__all__ = ['LoginPage', 'IndexPage', 'AccountsPage', 'TransactionsPage']
|
||||
|
||||
|
||||
class LoginPage(BasePage):
|
||||
def login(self, login, passwd):
|
||||
self.browser.select_form(name='Login')
|
||||
self.browser['IDToken1'] = login
|
||||
self.browser['IDToken2'] = passwd
|
||||
self.browser.submit(nologin=True)
|
||||
|
||||
class IndexPage(BasePage):
|
||||
def get_token(self):
|
||||
url = self.document.getroot().xpath('//frame[@name="portalHeader"]')[0].attrib['src']
|
||||
v = urlsplit(url)
|
||||
args = dict(parse_qsl(v.query))
|
||||
return args['token']
|
||||
|
||||
class AccountsPage(BasePage):
|
||||
ACCOUNT_TYPES = {u'Mes comptes d\'épargne': Account.TYPE_SAVINGS,
|
||||
u'Mes comptes': Account.TYPE_CHECKING,
|
||||
}
|
||||
|
||||
def get_list(self):
|
||||
account_type = Account.TYPE_UNKNOWN
|
||||
|
||||
params = {}
|
||||
for field in self.document.xpath('//input'):
|
||||
params[field.attrib['name']] = field.attrib.get('value', '')
|
||||
|
||||
for div in self.document.xpath('//div[@class="btit"]'):
|
||||
account_type = self.ACCOUNT_TYPES.get(div.text.strip(), Account.TYPE_UNKNOWN)
|
||||
|
||||
for tr in div.getnext().xpath('.//tbody/tr'):
|
||||
args = dict(parse_qsl(tr.attrib['id']))
|
||||
tds = tr.findall('td')
|
||||
|
||||
account = Account()
|
||||
account.id = args['identifiant']
|
||||
account.label = u''.join([txt.strip() for txt in tds[2].itertext()])
|
||||
account.type = account_type
|
||||
link = tds[3].find('a')
|
||||
account.balance = Decimal(link.find('span').text.strip().replace(' ', '').replace(',', '.'))
|
||||
account._params = params.copy()
|
||||
account._params['dialogActionPerformed'] = 'SOLDE'
|
||||
account._params['attribute($SEL_$%s)' % tr.attrib['id'].split('_')[0]] = tr.attrib['id'].split('_', 1)[1]
|
||||
yield account
|
||||
|
||||
return
|
||||
|
||||
class Transaction(FrenchTransaction):
|
||||
PATTERNS = [(re.compile('^RET DAB (?P<text>.*?) RETRAIT DU (?P<dd>\d{2})(?P<mm>\d{2})(?P<yy>\d{2}).*'),
|
||||
FrenchTransaction.TYPE_WITHDRAWAL),
|
||||
(re.compile('^RET DAB (?P<text>.*?) CARTE ?:.*'),
|
||||
FrenchTransaction.TYPE_WITHDRAWAL),
|
||||
(re.compile('(\w+) (?P<dd>\d{2})(?P<mm>\d{2})(?P<yy>\d{2}) CB:[^ ]+ (?P<text>.*)'),
|
||||
FrenchTransaction.TYPE_CARD),
|
||||
(re.compile('^VIR(EMENT)? (?P<text>.*)'), FrenchTransaction.TYPE_TRANSFER),
|
||||
(re.compile('^PRLV (?P<text>.*)'), FrenchTransaction.TYPE_ORDER),
|
||||
(re.compile('^CHEQUE.*'), FrenchTransaction.TYPE_CHECK),
|
||||
(re.compile('^(CONVENTION \d+ )?COTIS(ATION)? (?P<text>.*)'),
|
||||
FrenchTransaction.TYPE_BANK),
|
||||
(re.compile('^REMISE (?P<text>.*)'), FrenchTransaction.TYPE_DEPOSIT),
|
||||
(re.compile('^(?P<text>.*)( \d+)? QUITTANCE .*'),
|
||||
FrenchTransaction.TYPE_ORDER),
|
||||
(re.compile('^.* LE (?P<dd>\d{2})/(?P<mm>\d{2})/(?P<yy>\d{2})$'),
|
||||
FrenchTransaction.TYPE_UNKNOWN),
|
||||
]
|
||||
|
||||
|
||||
class TransactionsPage(BasePage):
|
||||
def get_next_params(self):
|
||||
if len(self.document.xpath('//li[@id="tbl1_nxt"]')) == 0:
|
||||
return None
|
||||
|
||||
params = {}
|
||||
for field in self.document.xpath('//input'):
|
||||
params[field.attrib['name']] = field.attrib.get('value', '')
|
||||
|
||||
params['validationStrategy'] = 'NV'
|
||||
params['pagingDirection'] = 'NEXT'
|
||||
params['pagerName'] = 'tbl1'
|
||||
|
||||
return params
|
||||
|
||||
def get_history(self):
|
||||
for tr in self.document.xpath('//table[@id="tbl1"]/tbody/tr'):
|
||||
tds = tr.findall('td')
|
||||
|
||||
t = Transaction(tr.attrib['id'].split('_', 1)[1])
|
||||
|
||||
date = u''.join([txt.strip() for txt in tds[4].itertext()])
|
||||
raw = u' '.join([txt.strip() for txt in tds[1].itertext()])
|
||||
debit = u''.join([txt.strip() for txt in tds[-2].itertext()])
|
||||
credit = u''.join([txt.strip() for txt in tds[-1].itertext()])
|
||||
t.parse(date, re.sub(r'[ ]+', ' ', raw))
|
||||
t.set_amount(credit, debit)
|
||||
yield t
|
||||
30
modules/banquepopulaire/test.py
Normal file
30
modules/banquepopulaire/test.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2012 Romain Bignon
|
||||
#
|
||||
# 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 weboob.tools.test import BackendTest
|
||||
|
||||
class BanquePopulaireTest(BackendTest):
|
||||
BACKEND = 'banquepopulaire'
|
||||
|
||||
def test_banquepop(self):
|
||||
l = list(self.backend.iter_accounts())
|
||||
if len(l) > 0:
|
||||
a = l[0]
|
||||
list(self.backend.iter_history(a))
|
||||
Loading…
Add table
Add a link
Reference in a new issue