From ae3ccde2e896ea84490228359a52af1f83b75108 Mon Sep 17 00:00:00 2001 From: Florent Date: Wed, 18 Apr 2012 14:06:34 +0200 Subject: [PATCH] Get more historical transactions We get now all availables transactions on the website, not only the first page --- modules/ing/browser.py | 12 +++++++---- modules/ing/pages/account_history.py | 31 ++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/modules/ing/browser.py b/modules/ing/browser.py index 02e68249..d405d936 100644 --- a/modules/ing/browser.py +++ b/modules/ing/browser.py @@ -91,7 +91,11 @@ class Ing(BaseBrowser): self.location('https://secure.ingdirect.fr/general?command=goToAccount&account=%d&zone=COMPTE' % int(id)) else: raise NotImplementedError() - return self.page.get_transactions() - - # TODO - # def get_coming_operations + while 1: + for transaction in self.page.get_transactions(): + yield transaction + if self.page.islast(): + return + self.page.next_page() + # The answer is not a valide html page for mechanize, we have to be tolerant + self._factory.is_html = True diff --git a/modules/ing/pages/account_history.py b/modules/ing/pages/account_history.py index 03ab699d..077af0ae 100644 --- a/modules/ing/pages/account_history.py +++ b/modules/ing/pages/account_history.py @@ -23,6 +23,7 @@ from decimal import Decimal from datetime import date from weboob.tools.browser import BasePage +from weboob.tools.mech import ClientForm from weboob.capabilities.bank import Transaction from weboob.tools.capabilities.bank.transactions import FrenchTransaction @@ -47,15 +48,33 @@ class AccountHistory(BasePage): i = 1 for tr in table.xpath('tr'): id = i - texte = tr.text_content().split('\n') op = Transaction(id) - op.parse(date = date(*reversed([int(x) for x in texte[0].split('/')])), - raw = texte[2]) + textdate = tr.find('td[@class="op_date"]').text_content() + textraw = tr.find('td[@class="op_label"]').text_content() + op.parse(date = date(*reversed([int(x) for x in textdate.split('/')])), + raw = textraw) # force the use of website category - op.category = texte[4] + op.category = unicode(tr.find('td[@class="op_type"]').text) - op.amount = Decimal(op.clean_amount(texte[5])) - print "coin" + op.amount = Decimal(op.clean_amount(tr.find('td[@class="op_amount"]').text_content())) i += 1 + yield op + def islast(self): + form = self.document.find('//form[@id="navigation_form"]') + alinks = form.xpath('div/a') + for a in alinks: + if u'Page Suivante' in a.text: + self.next = a.attrib['id'] + return False + return True + + def next_page(self): + self.browser.select_form('navigation_form') + self.browser.set_all_readonly(False) + self.browser.controls.append(ClientForm.TextControl('text', 'AJAXREQUEST', {'value': ''})) + self.browser['AJAXREQUEST'] = '_viewRoot' + self.browser.controls.append(ClientForm.TextControl('text', self.next, {'value': ''})) + self.browser[self.next] = self.next + self.browser.submit()