Commit ad7c2c53 authored by Romain Bignon's avatar Romain Bignon

support international accounts

parent 0aa4fd3e
......@@ -21,7 +21,7 @@ from __future__ import with_statement
from import ICapBank, AccountNotFound
from import BaseBackend, BackendConfig
from import ValueBackendPassword
from import ValueBackendPassword, Value
from .browser import HSBC
......@@ -37,12 +37,14 @@ class HSBCBackend(BaseBackend, ICapBank):
DESCRIPTION = 'HSBC France bank website'
CONFIG = BackendConfig(ValueBackendPassword('login', label='Account ID', masked=False),
ValueBackendPassword('password', label='Password', regexp='^(\d+|)$'))
ValueBackendPassword('password', label='Password'),
Value( 'secret', label='Secret (optional)', default=''))
def create_default_browser(self):
return self.create_browser(self.config['login'].get(),
def iter_accounts(self):
for account in self.browser.get_accounts_list():
......@@ -25,6 +25,7 @@ import re
from import LinearDateGuesser
from import BaseBrowser, BrowserIncorrectPassword, BasePage, BrokenPageError
from .pages.accounts import AccountsListPage, CPTHistoryPage, CardHistoryPage
from .pages.login import LoginPage
__all__ = ['HSBC']
......@@ -43,21 +44,34 @@ class HSBC(BaseBrowser):
'\?.*debr=COMPTES_PAN': AccountsListPage,
'\?.*CPT_IdPrestation=.*': CPTHistoryPage,
'\?.*CB_IdPrestation=.*': CardHistoryPage,
'*': LoginPage,
'': LoginPage,
_session = None
def __init__(self, username, password, secret, *args, **kwargs):
self.secret = secret
BaseBrowser.__init__(self, username, password, *args, **kwargs)
def home(self):
def is_logged(self):
return self._session is not None and not self.is_on_page(NotLoggedPage)
return self._session is not None and not self.is_on_page((NotLoggedPage,LoginPage))
def login(self):
assert isinstance(self.username, basestring)
assert isinstance(self.password, basestring)
assert self.password.isdigit()
if len(self.username) == 11 and self.username.isdigit():
def login_france(self):
data = {'Ident': self.username}
r = self.readurl('', urllib.urlencode(data), if_fail='raise')
m ='sessionid=([^ "]+)', r, flags=re.MULTILINE)
......@@ -74,8 +88,28 @@ class HSBC(BaseBrowser):
m ='url = "/cgi-bin/emcgi\?sessionid=([^& "]+)&debr="', r, flags=re.MULTILINE)
if not m:
raise BrokenPageError('Unable to find session token')
self._session =
def login_world(self):
data = {'Appl': 'WEBACC',
'CODE_ABONNE': self.username,
'Ident': self.username,
'ifr': 0,
'nextPage': 'localsso.hbfr.Redirect',
'secret': '',
'userid': self.username,
self.location('', urllib.urlencode(data), no_login=True), self.secret, self.password)
error =
if error is not None:
raise BrowserIncorrectPassword(error)
self._session =
def get_accounts_list(self):
self.location(self.buildurl('/cgi-bin/emcgi', sessionid=self._session, debr='COMPTES_PAN'))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment