diff --git a/modules/banquepopulaire/__init__.py b/modules/banquepopulaire/__init__.py
new file mode 100644
index 00000000..42d43215
--- /dev/null
+++ b/modules/banquepopulaire/__init__.py
@@ -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 .
+
+
+from .backend import BanquePopulaireBackend
+
+__all__ = ['BanquePopulaireBackend']
diff --git a/modules/banquepopulaire/backend.py b/modules/banquepopulaire/backend.py
new file mode 100644
index 00000000..ff231472
--- /dev/null
+++ b/modules/banquepopulaire/backend.py
@@ -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 .
+
+
+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)
diff --git a/modules/banquepopulaire/browser.py b/modules/banquepopulaire/browser.py
new file mode 100644
index 00000000..0fdbad91
--- /dev/null
+++ b/modules/banquepopulaire/browser.py
@@ -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 .
+
+
+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))
diff --git a/modules/banquepopulaire/favicon.png b/modules/banquepopulaire/favicon.png
new file mode 100644
index 00000000..38389e7d
Binary files /dev/null and b/modules/banquepopulaire/favicon.png differ
diff --git a/modules/banquepopulaire/pages.py b/modules/banquepopulaire/pages.py
new file mode 100644
index 00000000..0c726c97
--- /dev/null
+++ b/modules/banquepopulaire/pages.py
@@ -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 .
+
+
+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.*?) RETRAIT DU (?P\d{2})(?P\d{2})(?P\d{2}).*'),
+ FrenchTransaction.TYPE_WITHDRAWAL),
+ (re.compile('^RET DAB (?P.*?) CARTE ?:.*'),
+ FrenchTransaction.TYPE_WITHDRAWAL),
+ (re.compile('(\w+) (?P\d{2})(?P\d{2})(?P\d{2}) CB:[^ ]+ (?P.*)'),
+ FrenchTransaction.TYPE_CARD),
+ (re.compile('^VIR(EMENT)? (?P.*)'), FrenchTransaction.TYPE_TRANSFER),
+ (re.compile('^PRLV (?P.*)'), FrenchTransaction.TYPE_ORDER),
+ (re.compile('^CHEQUE.*'), FrenchTransaction.TYPE_CHECK),
+ (re.compile('^(CONVENTION \d+ )?COTIS(ATION)? (?P.*)'),
+ FrenchTransaction.TYPE_BANK),
+ (re.compile('^REMISE (?P.*)'), FrenchTransaction.TYPE_DEPOSIT),
+ (re.compile('^(?P.*)( \d+)? QUITTANCE .*'),
+ FrenchTransaction.TYPE_ORDER),
+ (re.compile('^.* LE (?P\d{2})/(?P\d{2})/(?P\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
diff --git a/modules/banquepopulaire/test.py b/modules/banquepopulaire/test.py
new file mode 100644
index 00000000..61a9db28
--- /dev/null
+++ b/modules/banquepopulaire/test.py
@@ -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 .
+
+
+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))