bred: ability to select accounts

This commit is contained in:
Romain Bignon 2013-08-07 10:57:23 +02:00
commit fe6d99c51a
3 changed files with 32 additions and 4 deletions

View file

@ -21,7 +21,7 @@
from weboob.capabilities.bank import ICapBank, AccountNotFound from weboob.capabilities.bank import ICapBank, AccountNotFound
from weboob.tools.backend import BaseBackend, BackendConfig from weboob.tools.backend import BaseBackend, BackendConfig
from weboob.tools.value import ValueBackendPassword from weboob.tools.value import ValueBackendPassword, Value
from .browser import BredBrowser from .browser import BredBrowser
@ -37,11 +37,15 @@ class BredBackend(BaseBackend, ICapBank):
DESCRIPTION = u'BRED French bank website' DESCRIPTION = u'BRED French bank website'
LICENSE = 'AGPLv3+' LICENSE = 'AGPLv3+'
CONFIG = BackendConfig(ValueBackendPassword('login', label='Account ID', masked=False), CONFIG = BackendConfig(ValueBackendPassword('login', label='Account ID', masked=False),
ValueBackendPassword('password', label='Password of account')) ValueBackendPassword('password', label='Password of account'),
Value('accnum', label='Account number to force (optional)', default='', masked=False)
)
BROWSER = BredBrowser BROWSER = BredBrowser
def create_default_browser(self): def create_default_browser(self):
return self.create_browser(self.config['login'].get(), self.config['password'].get()) return self.create_browser(self.config['accnum'].get(),
self.config['login'].get(),
self.config['password'].get())
def iter_accounts(self): def iter_accounts(self):
with self.browser: with self.browser:

View file

@ -41,6 +41,10 @@ class BredBrowser(BaseBrowser):
'https://www.bred.fr/': EmptyPage, 'https://www.bred.fr/': EmptyPage,
} }
def __init__(self, accnum, *args, **kwargs):
self.accnum = accnum.zfill(11)
BaseBrowser.__init__(self, *args, **kwargs)
def is_logged(self): def is_logged(self):
return self.page is not None and not self.is_on_page(LoginPage) return self.page is not None and not self.is_on_page(LoginPage)

View file

@ -55,7 +55,27 @@ class LoginResultPage(BasePage):
pass pass
else: else:
self.browser.set_all_readonly(False) self.browser.set_all_readonly(False)
self.browser['typeCompte'] = 'P' accounts = {}
for tr in self.document.getroot().cssselect('table.compteTable tbody tr'):
attr = tr.xpath('.//a')[0].attrib.get('onclick', '')
m = re.search("value = '(\w+)';checkAndSubmit\('\w+','(\w+)','(\w+)'\)", attr)
if m:
typeCompte = m.group(1)
tagName = m.group(2)
value = self.document.xpath('//input[@id="%s%s"]' % (m.group(2), m.group(3)))[0].attrib['value']
accounts[value] = (typeCompte, tagName)
try:
typeCompte, tagName = accounts[self.browser.accnum]
value = self.browser.accnum
except KeyError:
if self.browser.accnum != '00000000000':
self.logger.warning(u'Unable to find account "%s". Available ones: %s' % (self.browser.accnum, ', '.join(accounts.keys())))
elif len(accounts) > 1:
self.logger.warning('There are several accounts, please use "accnum" backend parameter to force the one to use')
value, (typeCompte, tagName) = accounts.popitem()
self.browser['typeCompte'] = typeCompte
self.browser[tagName] = [value]
self.browser.submit() self.browser.submit()