From 4df089ee1b580975f4374ff3b6c723c248cc4d0a Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Sat, 23 Feb 2013 13:15:05 +0100 Subject: [PATCH] get maximum history --- modules/boursorama/browser.py | 25 ++++++++------------- modules/boursorama/pages/account_history.py | 16 +++++++++++++ 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/modules/boursorama/browser.py b/modules/boursorama/browser.py index cbe437bb..f357cf1f 100644 --- a/modules/boursorama/browser.py +++ b/modules/boursorama/browser.py @@ -22,9 +22,6 @@ from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword from .pages import LoginPage, AccountsList, AccountHistory, UpdateInfoPage -from datetime import date -from dateutil.relativedelta import relativedelta - __all__ = ['Boursorama'] @@ -83,21 +80,17 @@ class Boursorama(BaseBrowser): return None def get_history(self, account): - self.location(account._link_id) - if not self.is_on_page(AccountHistory): - raise NotImplementedError() + link = account._link_id - operations = self.page.get_operations() - # load last month as well - target = date.today() - relativedelta(months=1) - self.location(account._link_id + ("&month=%d&year=%d" % (target.month, target.year))) - operations += self.page.get_operations() - # and the month before, just in case you're greedy - target = date.today() - relativedelta(months=2) - self.location(account._link_id + ("&month=%d&year=%d" % (target.month, target.year))) - operations += self.page.get_operations() + while link is not None: + self.location(link) + if not self.is_on_page(AccountHistory): + raise NotImplementedError() - return operations + for tr in self.page.get_operations(): + yield tr + + link = self.page.get_next_url() def transfer(self, from_id, to_id, amount, reason=None): raise NotImplementedError() diff --git a/modules/boursorama/pages/account_history.py b/modules/boursorama/pages/account_history.py index 871da3c9..faa3c84b 100644 --- a/modules/boursorama/pages/account_history.py +++ b/modules/boursorama/pages/account_history.py @@ -19,6 +19,7 @@ # along with weboob. If not, see . +from urlparse import urlparse from datetime import date import re @@ -79,3 +80,18 @@ class AccountHistory(BasePage): def get_operations(self): return self.operations + + def get_next_url(self): + items = self.document.getroot().cssselect('ul.mainmenu li') + + current = False + for li in reversed(items): + if li.attrib.get('class', '') == 'selected': + current = True + elif current: + a = li.find('a') + if 'year' in a.attrib.get('href', ''): + url = urlparse(self.url) + return url.path + a.attrib['href'] + else: + return None