From ca4c97b42f3a6eb478d990d22268822fa54fdc9f Mon Sep 17 00:00:00 2001 From: Laurent Bachelier Date: Tue, 12 Feb 2013 18:29:01 +0100 Subject: [PATCH] paypal: Handle multiple pages --- modules/paypal/browser.py | 7 +++++-- modules/paypal/pages.py | 14 ++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/modules/paypal/browser.py b/modules/paypal/browser.py index f89bc265..8e107ffc 100644 --- a/modules/paypal/browser.py +++ b/modules/paypal/browser.py @@ -76,8 +76,11 @@ class Paypal(BaseBrowser): def get_history(self, account): self.history() - for transaction in self.page.iter_transactions(account): - yield transaction + parse = True + while parse: + for trans in self.page.iter_transactions(account): + yield trans + parse = self.page.next() def history(self): self.location('/en/cgi-bin/webscr?cmd=_history&nav=0.3.0') diff --git a/modules/paypal/pages.py b/modules/paypal/pages.py index 796da567..3926f5cd 100644 --- a/modules/paypal/pages.py +++ b/modules/paypal/pages.py @@ -121,9 +121,9 @@ class AccountPage(BasePage): class DownloadHistoryPage(BasePage): - def download(self): + def download(self, days=90): today = datetime.date.today() - start = today - datetime.timedelta(days=90) + start = today - datetime.timedelta(days) self.browser.select_form(name='form1') self.browser['to_c'] = str(today.year) self.browser['to_a'] = str(today.month) @@ -246,16 +246,22 @@ class HistoryPage(BasePage): time_format = "%H:%M:%S" return date_format, time_format, months - def filter(self): + def filter(self, days=90): date_format = self.guess_format()[0] today = datetime.date.today() - start = today - datetime.timedelta(days=90) + start = today - datetime.timedelta(days) self.browser.select_form(name='history') self.browser['dateoption'] = ['dateselect'] self.browser['from_date'] = start.strftime(date_format) self.browser['to_date'] = today.strftime(date_format) self.browser.submit(name='show') + def next(self): + if self.document.xpath('//span[@class="pageNext"]'): + self.browser.select_form(name='history') + self.browser.submit(name='next') + return True + def parse(self): emonths = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August',