diff --git a/modules/banqueaccord/backend.py b/modules/banqueaccord/backend.py index a0247934..cb761bad 100644 --- a/modules/banqueaccord/backend.py +++ b/modules/banqueaccord/backend.py @@ -18,7 +18,7 @@ # along with weboob. If not, see . -from weboob.capabilities.bank import ICapBank +from weboob.capabilities.bank import ICapBank, AccountNotFound from weboob.tools.backend import BaseBackend, BackendConfig from weboob.tools.value import ValueBackendPassword @@ -46,10 +46,16 @@ class BanqueAccordBackend(BaseBackend, ICapBank): def iter_accounts(self): with self.browser: - return [self.browser.get_account()] + return self.browser.get_accounts_list() - def get_account(self, id): - return self.browser.get_account() + 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: diff --git a/modules/banqueaccord/browser.py b/modules/banqueaccord/browser.py index dd7b2bde..ee5294d7 100644 --- a/modules/banqueaccord/browser.py +++ b/modules/banqueaccord/browser.py @@ -18,8 +18,9 @@ # along with weboob. If not, see . +import urllib + from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword -from weboob.capabilities.bank import Account from .pages import LoginPage, IndexPage, AccountsPage, OperationsPage @@ -67,21 +68,32 @@ class BanqueAccordBrowser(BaseBrowser): if not self.is_logged(): raise BrowserIncorrectPassword() + def get_accounts_list(self): + if not self.is_on_page(IndexPage): + self.location('https://www.banque-accord.fr/site/s/detailcompte/detailcompte.html') - def get_account(self): + for a in self.page.get_list(): + post = {'numeroCompte': a.id,} + self.location('/site/s/detailcompte/detailcompte.html', urllib.urlencode(post)) + self.location('/site/s/detailcompte/ongletdetailcompte.html') + a.balance = self.page.get_balance() + yield a + + + + def get_account(self, id): + assert isinstance(id, basestring) if not self.is_on_page(IndexPage): self.home() - account = Account() - account.id = '0' - account.label = self.page.get_card_name() - - self.location('/site/s/detailcompte/ongletdetailcompte.html') - account.balance = self.page.get_balance() - - return account + for a in self.get_accounts_list(): + if a.id == id: + return a + return None def iter_history(self, account): + post = {'numeroCompte': account.id,} + self.location('/site/s/detailcompte/detailcompte.html', urllib.urlencode(post)) self.location('/site/s/detailcompte/ongletdernieresoperations.html') assert self.is_on_page(OperationsPage) diff --git a/modules/banqueaccord/pages.py b/modules/banqueaccord/pages.py index 0844baa0..eafcbef1 100644 --- a/modules/banqueaccord/pages.py +++ b/modules/banqueaccord/pages.py @@ -21,6 +21,7 @@ from decimal import Decimal import re +from weboob.capabilities.bank import Account from weboob.tools.browser import BasePage, BrokenPageError from weboob.tools.captcha.virtkeyboard import MappedVirtKeyboard, VirtKeyboardError from weboob.tools.capabilities.bank.transactions import FrenchTransaction @@ -88,6 +89,15 @@ class LoginPage(BasePage): self.browser.location(self.browser.buildurl(form.attrib['action'], identifiant=login, code=code), no_login=True) class IndexPage(BasePage): + def get_list(self): + for line in self.document.xpath('//li[@id="menu-n2-mesproduits"]//li//a'): + if line.get('onclick') is None: + continue + account = Account() + account.id = line.get('onclick').split("'")[1] + account.label = self.parser.tocleanstring(line) + yield account + def get_card_name(self): return self.parser.tocleanstring(self.document.xpath('//h1')[0])