get maximum history

This commit is contained in:
Romain Bignon 2013-02-23 13:15:05 +01:00
commit 4df089ee1b
2 changed files with 27 additions and 18 deletions

View file

@ -22,9 +22,6 @@
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
from .pages import LoginPage, AccountsList, AccountHistory, UpdateInfoPage from .pages import LoginPage, AccountsList, AccountHistory, UpdateInfoPage
from datetime import date
from dateutil.relativedelta import relativedelta
__all__ = ['Boursorama'] __all__ = ['Boursorama']
@ -83,21 +80,17 @@ class Boursorama(BaseBrowser):
return None return None
def get_history(self, account): def get_history(self, account):
self.location(account._link_id) link = account._link_id
if not self.is_on_page(AccountHistory):
raise NotImplementedError()
operations = self.page.get_operations() while link is not None:
# load last month as well self.location(link)
target = date.today() - relativedelta(months=1) if not self.is_on_page(AccountHistory):
self.location(account._link_id + ("&month=%d&year=%d" % (target.month, target.year))) raise NotImplementedError()
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()
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): def transfer(self, from_id, to_id, amount, reason=None):
raise NotImplementedError() raise NotImplementedError()

View file

@ -19,6 +19,7 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>. # along with weboob. If not, see <http://www.gnu.org/licenses/>.
from urlparse import urlparse
from datetime import date from datetime import date
import re import re
@ -79,3 +80,18 @@ class AccountHistory(BasePage):
def get_operations(self): def get_operations(self):
return self.operations 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