From f8bf995cfd87475b06497030cdb22b06dfafb64a Mon Sep 17 00:00:00 2001 From: Laurent Bachelier Date: Tue, 23 Jul 2013 20:25:32 +0200 Subject: [PATCH] bnporc[ent]: Account list --- modules/bnporc/enterprise/browser.py | 12 +++++-- modules/bnporc/enterprise/pages.py | 47 +++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/modules/bnporc/enterprise/browser.py b/modules/bnporc/enterprise/browser.py index b18f8e36..281650cc 100644 --- a/modules/bnporc/enterprise/browser.py +++ b/modules/bnporc/enterprise/browser.py @@ -31,7 +31,7 @@ class BNPEnterprise(BaseBrowser): CERTHASH = '423f68a8162d1328bacb48269675d8b8577ebcc9d222860de8421792c4d222c1' PAGES = {'%s://%s/NSAccess.*' % (PROTOCOL, DOMAIN): LoginPage, - '%s://%s/UNE\?Action=DSP_VGLOBALE' % (PROTOCOL, DOMAIN): AccountsPage} + '%s://%s/UNE\?.*' % (PROTOCOL, DOMAIN): AccountsPage} def home(self): self.location('%s://%s/NSAccess' % (self.PROTOCOL, self.DOMAIN)) @@ -51,7 +51,15 @@ class BNPEnterprise(BaseBrowser): self.home() self.page.login(self.username, self.password) - self.location('/UNE?Action=DSP_VGLOBALE', no_login=True) + self.location('/UNE?ch6=0&ch8=2000&chA=1&chh=O', no_login=True) if not self.is_logged(): raise BrowserIncorrectPassword() + + def get_accounts_list(self): + # options shows accounts in their original currency + # it's the "en capitaux" mode, not sure if it's the best + # the "en valeur" mode is ch8=1000 + self.location('/UNE?ch6=0&ch8=2000&chA=1&chh=O') + for account in self.page.get_list(): + yield account diff --git a/modules/bnporc/enterprise/pages.py b/modules/bnporc/enterprise/pages.py index 922f4021..688f3f36 100644 --- a/modules/bnporc/enterprise/pages.py +++ b/modules/bnporc/enterprise/pages.py @@ -17,14 +17,25 @@ # You should have received a copy of the GNU Affero General Public License # along with weboob. If not, see . -from weboob.tools.browser import BasePage -from weboob.tools.captcha.virtkeyboard import MappedVirtKeyboard, VirtKeyboardError - +from decimal import Decimal import hashlib +from urlparse import parse_qs +from datetime import datetime + +from weboob.capabilities.bank import Account +from weboob.tools.browser import BasePage +from weboob.tools.capabilities.bank.transactions import FrenchTransaction +from weboob.tools.captcha.virtkeyboard import MappedVirtKeyboard, VirtKeyboardError +from weboob.tools.misc import to_unicode + __all__ = ['LoginPage', 'AccountsPage'] +class Transaction(FrenchTransaction): + pass + + class BEPage(BasePage): def get_error(self): for title in self.document.xpath('/html/head/title'): @@ -103,4 +114,32 @@ class LoginPage(BEPage): class AccountsPage(BEPage): - pass + def find_table(self): + for table in self.parser.select(self.document.getroot(), 'table', 'many'): + for td in self.parser.select(table, 'tr td'): + if td.text and td.text.strip().startswith('COMPTES COURANTS'): + return table + + def get_list(self): + table = self.find_table() + # skip first tr + trs = self.parser.select(table, 'tr') + for tr in trs: + tds = self.parser.select(tr, 'td') + if len(tds) != 6: + continue + tdlabel, tdid, tdcur, tdupdated, tdbal, tdbalcur = tds + + account = Account() + account.label = to_unicode(tdlabel.text_content().strip()) + # this is important - and is also the last part of the id (considering spaces) + # we can't use only the link as it does not goes where we want + link = self.parser.select(tdlabel, 'a', 1) + account._link_id = parse_qs(link.attrib['href'])['ch4'][0] + account.id = to_unicode(tdid.text.strip().replace(' ', '')) + # just in case we are showing the converted balances + account._main_currency = Account.get_currency(tdcur.text) + account.balance = Decimal(Transaction.clean_amount(tdbal.text_content())) + account.currency = Account.get_currency(tdbalcur.text) + account._updated = datetime.strptime(tdupdated.text, '%d/%m/%Y') + yield account