From 3d532ef50193f8fb17e88114a9e25301c604022c Mon Sep 17 00:00:00 2001 From: Florent Date: Fri, 22 Feb 2013 17:58:50 +0100 Subject: [PATCH] Support all the history Ugly code... --- modules/ing/browser.py | 18 +++++++++++++----- modules/ing/pages/accounts_list.py | 18 ++++++++++++++++-- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/modules/ing/browser.py b/modules/ing/browser.py index 91595323..d4e29975 100644 --- a/modules/ing/browser.py +++ b/modules/ing/browser.py @@ -121,19 +121,26 @@ class Ing(BaseBrowser): } self.location(self.accountspage, urllib.urlencode(data)) self.where = "history" + jid = self.page.get_history_jid() + i = 0 # index, we get always the same page, but with more informations while 1: hashlist = [] - for transaction in self.page.get_transactions(): + for transaction in self.page.get_transactions(i): while transaction.id in hashlist: transaction.id = hashlib.md5(transaction.id + "1").hexdigest() hashlist.append(transaction.id) + i += 1 yield transaction if self.page.islast(): return - - # XXX server sends an unknown mimetype, we overload - # viewing_html() above to prevent this issue. - self.page.next_page() + data = {"AJAX:EVENTS_COUNT": 1, + "AJAXREQUEST": "_viewRoot", + "autoScroll": "", + "index": "index", + "index:%s:moreTransactions" % jid: "index:%s:moreTransactions" % jid, + "javax.faces.ViewState": account._jid + } + self.location(self.accountspage, urllib.urlencode(data)) def get_recipients(self, account): if not self.is_on_page(TransferPage): @@ -184,6 +191,7 @@ class Ing(BaseBrowser): yield bill if self.page.islast(): return + self.page.next_page() def predownload(self, bill): diff --git a/modules/ing/pages/accounts_list.py b/modules/ing/pages/accounts_list.py index 55064a2f..9045cafb 100644 --- a/modules/ing/pages/accounts_list.py +++ b/modules/ing/pages/accounts_list.py @@ -72,12 +72,17 @@ class AccountsList(BasePage): account._jid = jid.attrib['value'] yield account - def get_transactions(self): + def get_transactions(self, index): + i = 0 for table in self.document.xpath('//table[@cellpadding="0"]'): try: textdate = table.find('.//td[@class="elmt tdate"]').text_content() except AttributeError: continue + # Do not parse transactions already parsed + if i < index: + i += 1 + continue if textdate == 'hier': textdate = (date.today() - timedelta(days=1)).strftime('%d/%m/%Y') elif textdate == "aujourd'hui": @@ -102,5 +107,14 @@ class AccountsList(BasePage): op.amount = Decimal(amount) yield op + def get_history_jid(self): + span = self.document.xpath('//span[starts-with(@id, "index:j_id")]')[0] + jid = span.attrib['id'].split(':')[1] + return jid + def islast(self): - return True + nomore = self.document.xpath('//span[@class="no-more-transactions"]') + if len(nomore) > 0: + return True + else: + return False