From 9760ca6e23eda98161c002f84c8a7af16a943bee Mon Sep 17 00:00:00 2001 From: Laurent Bachelier Date: Wed, 24 Jul 2013 17:52:33 +0200 Subject: [PATCH] bnporc[ent]: Get history Only the last day for now --- modules/bnporc/enterprise/browser.py | 17 ++++++++++-- modules/bnporc/enterprise/pages.py | 40 +++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/modules/bnporc/enterprise/browser.py b/modules/bnporc/enterprise/browser.py index 505e3e66..6961d884 100644 --- a/modules/bnporc/enterprise/browser.py +++ b/modules/bnporc/enterprise/browser.py @@ -20,7 +20,7 @@ from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword -from .pages import LoginPage, AccountsPage, UnknownPage +from .pages import LoginPage, AccountsPage, HistoryPage, UnknownPage __all__ = ['BNPEnterprise'] @@ -32,6 +32,7 @@ class BNPEnterprise(BaseBrowser): PAGES = {'%s://%s/NSAccess.*' % (PROTOCOL, DOMAIN): LoginPage, '%s://%s/UNE\?.*' % (PROTOCOL, DOMAIN): AccountsPage, + '%s://%s/ROP\?Action=F_RELCO.+' % (PROTOCOL, DOMAIN): HistoryPage, '%s://%s/NSFR' % (PROTOCOL, DOMAIN): UnknownPage} def home(self): @@ -61,6 +62,18 @@ class BNPEnterprise(BaseBrowser): # 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') + if not self.is_on_page(AccountsPage): + self.location('/UNE?ch6=0&ch8=2000&chA=1&chh=O') for account in self.page.get_list(): yield account + + def get_account(self, _id): + for a in self.get_accounts_list(): + if a.id == _id: + yield a + + def iter_history(self, account): + if not self.is_on_page(HistoryPage): + self.location('/ROP?Action=F_RELCO&ch4=%s&ch8=2000' % account._link_id) + for transaction in self.page.iter_history(): + yield transaction diff --git a/modules/bnporc/enterprise/pages.py b/modules/bnporc/enterprise/pages.py index d8040d70..952b2a45 100644 --- a/modules/bnporc/enterprise/pages.py +++ b/modules/bnporc/enterprise/pages.py @@ -122,9 +122,7 @@ class AccountsPage(BEPage): def get_list(self): table = self.find_table() - # skip first tr - trs = self.parser.select(table, 'tr') - for tr in trs: + for tr in self.parser.select(table, 'tr', 'many'): tds = self.parser.select(tr, 'td') if len(tds) != 6: continue @@ -149,5 +147,41 @@ class AccountsPage(BEPage): yield account +class HistoryPage(BEPage): + def is_empty(self): + for td in self.parser.select(self.document.getroot(), 'td.V11vertGras'): + if u'Aucune opération enregistrée' in to_unicode(td.text_content()): + return True + return False + + 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_content().strip() == 'OPERATIONS': + return table + + def iter_history(self): + if not self.is_empty(): + table = self.find_table() + for i, tr in enumerate(self.parser.select(table, 'tr', 'many')): + tds = self.parser.select(tr, 'td') + if len(tds) != 5 or self.parser.select(tr, 'td.thtitrefondbleu'): + continue + tddate, tdval, tdlabel, tddebit, tdcredit = \ + [t.text_content().replace(u'\xa0', ' ').strip() for t in tds] + if all((tddate, tdlabel, any((tddebit, tdcredit)))): + if tddebit: + tdamount = '- %s' % tddebit + else: + tdamount = tdcredit + t = Transaction(i) + t.set_amount(tdamount) + date = datetime.strptime(tddate, '%d/%m/%Y') + val = datetime.strptime(tdval, '%d/%m/%Y') + t.parse(date, tdlabel) + t._val = val # FIXME is it rdate? date? + yield t + + class UnknownPage(BEPage): pass