From c207b109ab5395826a1e7758a122affe6d7e7412 Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Sat, 23 Feb 2013 12:38:46 +0100 Subject: [PATCH] support pagination --- modules/cic/browser.py | 24 +++++++++--------------- modules/cic/pages.py | 25 ++++++++++++++++++++++--- modules/creditmutuel/browser.py | 19 +++++++++---------- modules/creditmutuel/pages.py | 25 ++++++++++++++++++++++--- 4 files changed, 62 insertions(+), 31 deletions(-) diff --git a/modules/cic/browser.py b/modules/cic/browser.py index 11207720..edaf7e5a 100644 --- a/modules/cic/browser.py +++ b/modules/cic/browser.py @@ -96,21 +96,20 @@ class CICBrowser(BaseBrowser): self.currentSubBank = url.path.lstrip('/').split('/')[0] def list_operations(self, page_url): - l_ret = [] - while page_url: - if page_url.startswith('/'): - self.location(page_url) - else: - self.location('https://%s/%s/fr/banque/%s' % (self.DOMAIN, self.currentSubBank, page_url)) + if page_url.startswith('/'): + self.location(page_url) + else: + self.location('https://%s/%s/fr/banque/%s' % (self.DOMAIN, self.currentSubBank, page_url)) + go_next = True + while go_next: if not self.is_on_page(OperationsPage): - break + return for op in self.page.get_history(): - l_ret.append(op) - page_url = self.page.next_page_url() + yield op - return l_ret + go_next = self.page.go_next() def get_history(self, account): transactions = [] @@ -190,8 +189,3 @@ class CICBrowser(BaseBrowser): transfer.recipient = to transfer.date = submit_date return transfer - - #def get_coming_operations(self, account): - # if not self.is_on_page(AccountComing) or self.page.account.id != account.id: - # self.location('/NS_AVEEC?ch4=%s' % account._link_id) - # return self.page.get_operations() diff --git a/modules/cic/pages.py b/modules/cic/pages.py index a9a91d50..f35c431f 100644 --- a/modules/cic/pages.py +++ b/modules/cic/pages.py @@ -146,9 +146,28 @@ class OperationsPage(BasePage): operation.set_amount(credit, debit) yield operation - def next_page_url(self): - """ TODO pouvoir passer à la page des opérations suivantes """ - return 0 + def go_next(self): + form = self.document.xpath('//form[@id="paginationForm"]') + if len(form) == 0: + return False + + text = self.parser.tocleanstring(form[0]) + m = re.search(u'(\d+) / (\d+)', text or '', flags=re.MULTILINE) + if not m: + return False + + cur = int(m.group(1)) + last = int(m.group(2)) + + if cur == last: + return False + + self.browser.select_form(name='paginationForm') + self.browser.set_all_readonly(False) + self.browser['page'] = str(cur + 1) + self.browser.submit() + + return True class CardPage(OperationsPage): def get_history(self): diff --git a/modules/creditmutuel/browser.py b/modules/creditmutuel/browser.py index 6d639c71..1d3290d0 100644 --- a/modules/creditmutuel/browser.py +++ b/modules/creditmutuel/browser.py @@ -97,21 +97,20 @@ class CreditMutuelBrowser(BaseBrowser): self.currentSubBank = url.path.lstrip('/').split('/')[0] def list_operations(self, page_url): - l_ret = [] - while page_url: - if page_url.startswith('/'): - self.location(page_url) - else: - self.location('https://%s/%s/fr/banque/%s' % (self.DOMAIN, self.currentSubBank, page_url)) + if page_url.startswith('/'): + self.location(page_url) + else: + self.location('https://%s/%s/fr/banque/%s' % (self.DOMAIN, self.currentSubBank, page_url)) + go_next = True + while go_next: if not self.is_on_page(OperationsPage): - break + return for op in self.page.get_history(): - l_ret.append(op) - page_url = self.page.next_page_url() + yield op - return l_ret + go_next = self.page.go_next() def get_history(self, account): transactions = [] diff --git a/modules/creditmutuel/pages.py b/modules/creditmutuel/pages.py index 0c5e8e9f..7fc3a87c 100644 --- a/modules/creditmutuel/pages.py +++ b/modules/creditmutuel/pages.py @@ -146,9 +146,28 @@ class OperationsPage(BasePage): operation.set_amount(credit, debit) yield operation - def next_page_url(self): - """ TODO pouvoir passer à la page des opérations suivantes """ - return 0 + def go_next(self): + form = self.document.xpath('//form[@id="paginationForm"]') + if len(form) == 0: + return False + + text = self.parser.tocleanstring(form[0]) + m = re.search(u'(\d+) / (\d+)', text or '', flags=re.MULTILINE) + if not m: + return False + + cur = int(m.group(1)) + last = int(m.group(2)) + + if cur == last: + return False + + self.browser.select_form(name='paginationForm') + self.browser.set_all_readonly(False) + self.browser['page'] = str(cur + 1) + self.browser.submit() + + return True class CardPage(OperationsPage): def get_history(self):