From d8a739f86f22841d0fbbd1b5741f855b778e951c Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Thu, 12 Aug 2010 17:54:57 +0200 Subject: [PATCH] applying patch from Olf to add the 'history' command to boobank and backends (refs #373) --- weboob/applications/boobank/boobank.py | 13 ++++ weboob/backends/bnporc/backend.py | 4 ++ weboob/backends/bnporc/browser.py | 9 ++- weboob/backends/bnporc/pages/__init__.py | 2 +- .../backends/bnporc/pages/account_history.py | 60 +++++++++++++++++++ weboob/capabilities/bank.py | 3 + 6 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 weboob/backends/bnporc/pages/account_history.py diff --git a/weboob/applications/boobank/boobank.py b/weboob/applications/boobank/boobank.py index 7c0b3073..5cfbc0c3 100644 --- a/weboob/applications/boobank/boobank.py +++ b/weboob/applications/boobank/boobank.py @@ -50,6 +50,19 @@ class Boobank(ConsoleApplication): else: logging.error(u'Error[%s]: %s\n%s' % (backend.name, error, backtrace)) + @ConsoleApplication.command('Display old operations') + def command_history(self, id): + id, backend_name = self.parse_id(id) + names = (backend_name,) if backend_name is not None else None + self.load_configured_backends(ICapBank, names=names) + + def do(backend): + account = backend.get_account(id) + return backend.iter_history(account) + + for backend, operation in self.do(do): + self.format(operation) + @ConsoleApplication.command('Display all future operations') def command_coming(self, id): id, backend_name = self.parse_id(id) diff --git a/weboob/backends/bnporc/backend.py b/weboob/backends/bnporc/backend.py index cd755595..7383bb87 100644 --- a/weboob/backends/bnporc/backend.py +++ b/weboob/backends/bnporc/backend.py @@ -53,6 +53,10 @@ class BNPorcBackend(BaseBackend, ICapBank): else: raise AccountNotFound() + def iter_history(self, account): + for history in self.browser.get_history(account): + yield history + def iter_operations(self, account): for coming in self.browser.get_coming_operations(account): yield coming diff --git a/weboob/backends/bnporc/browser.py b/weboob/backends/bnporc/browser.py index 54bf1c4d..e2d86f9d 100644 --- a/weboob/backends/bnporc/browser.py +++ b/weboob/backends/bnporc/browser.py @@ -25,7 +25,7 @@ class BNPorc(BaseBrowser): PROTOCOL = 'https' ENCODING = None # refer to the HTML encoding PAGES = {'.*identifiant=DOSSIER_Releves_D_Operation.*': pages.AccountsList, - '.*identifiant=DSP_HISTOCPT.*': pages.AccountHistory, + '.*SAF_ROP.*': pages.AccountHistory, '.*NS_AVEEC.*': pages.AccountComing, '.*NS_AVEDP.*': pages.AccountPrelevement, '.*Action=DSP_VGLOBALE.*': pages.LoginPage, @@ -70,11 +70,16 @@ class BNPorc(BaseBrowser): l = self.page.get_list() for a in l: - if a.id == id: + if long(a.id) == id: return a return None + def get_history(self, account): + if not self.is_on_page(pages.AccountHistory) or self.page.account.id != account.id: + self.location('/SAF_ROP?ch4=%s' % account.link_id) + return self.page.get_operations() + def get_coming_operations(self, account): if not self.is_on_page(pages.AccountComing) or self.page.account.id != account.id: self.location('/NS_AVEEC?ch4=%s' % account.link_id) diff --git a/weboob/backends/bnporc/pages/__init__.py b/weboob/backends/bnporc/pages/__init__.py index d54324c9..1148a9dc 100644 --- a/weboob/backends/bnporc/pages/__init__.py +++ b/weboob/backends/bnporc/pages/__init__.py @@ -18,7 +18,7 @@ from .accounts_list import AccountsList from .account_coming import AccountComing +from .account_history import AccountHistory from .login import LoginPage, ConfirmPage -class AccountHistory(AccountsList): pass class AccountPrelevement(AccountsList): pass diff --git a/weboob/backends/bnporc/pages/account_history.py b/weboob/backends/bnporc/pages/account_history.py new file mode 100644 index 00000000..fce6a30d --- /dev/null +++ b/weboob/backends/bnporc/pages/account_history.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- + +# Copyright(C) 2009-2010 Romain Bignon +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +from weboob.tools.browser import BasePage +from weboob.capabilities.bank import Operation + + +__all__ = ['AccountHistory'] + + +class AccountHistory(BasePage): + + def on_loaded(self): + self.operations = [] + + for tr in self.document.getiterator('tr'): + if tr.attrib.get('class', '') == 'hdoc1' or tr.attrib.get('class', '') == 'hdotc1': + tds = tr.findall('td') + if len(tds) != 4: + continue + date = u'' + date = tds[0].text + label = u'' + label += tds[1].text + label = label.replace(u'\xa0', u'') + for child in tds[1].getchildren(): + if child.text: label += child.text + if child.tail: label += child.tail + if tds[1].tail: label += tds[1].tail + label = label.strip() + amount = tds[2].text.replace('.', '').replace(',', '.') + # if we don't have exactly one '.', this is not a floatm try the next + operation = Operation() + if amount.count('.') != 1: + amount = tds[3].text.replace('.', '').replace(',', '.') + operation.amount = float(amount) + else: + operation.amount = - float(amount) + + operation.date = date + operation.label = label + self.operations.append(operation) + + def get_operations(self): + return self.operations diff --git a/weboob/capabilities/bank.py b/weboob/capabilities/bank.py index 153ce385..ef725c4d 100644 --- a/weboob/capabilities/bank.py +++ b/weboob/capabilities/bank.py @@ -97,3 +97,6 @@ class ICapBank(IBaseCap): def iter_operations(self, account): raise NotImplementedError() + + def iter_history(self, id): + raise NotImplementedError()