From efbc3b9ef6782707cadcfdd72639b8b80be181d6 Mon Sep 17 00:00:00 2001 From: Laurent Bachelier Date: Tue, 5 Feb 2013 11:19:23 +0100 Subject: [PATCH] paypal: Add function to download the CSV history --- modules/paypal/browser.py | 8 +++++++- modules/paypal/pages.py | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/modules/paypal/browser.py b/modules/paypal/browser.py index e098acfb..f2b60989 100644 --- a/modules/paypal/browser.py +++ b/modules/paypal/browser.py @@ -19,7 +19,7 @@ from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword -from .pages import LoginPage, AccountPage +from .pages import LoginPage, AccountPage, DownloadHistoryPage __all__ = ['Paypal'] @@ -34,6 +34,7 @@ class Paypal(BaseBrowser): '/cgi-bin/\?cmd=_login-run$': LoginPage, '/cgi-bin/\?cmd=_login-submit.+$': LoginPage, # wrong login '/cgi-bin/webscr\?cmd=_account&nav=0.0$': AccountPage, + '/cgi-bin/webscr\?cmd=_history-download&nav=0.3.1$': DownloadHistoryPage, } def home(self): @@ -70,5 +71,10 @@ class Paypal(BaseBrowser): def get_history(self, account): raise NotImplementedError() + def download_history(self): + self.location('/en/cgi-bin/webscr?cmd=_history-download&nav=0.3.1') + assert self.is_on_page(DownloadHistoryPage) + self.page.download() + def transfer(self, from_id, to_id, amount, reason=None): raise NotImplementedError() diff --git a/modules/paypal/pages.py b/modules/paypal/pages.py index b5cf7195..6d7a0139 100644 --- a/modules/paypal/pages.py +++ b/modules/paypal/pages.py @@ -19,6 +19,7 @@ from decimal import Decimal import re +import datetime from weboob.tools.browser import BasePage, BrokenPageError from weboob.capabilities.bank import Account @@ -113,3 +114,22 @@ class AccountPage(BasePage): accounts[account.id] = account return accounts + + +class DownloadHistoryPage(BasePage): + def download(self): + today = datetime.date.today() + self.browser.select_form(name='form1') + # download an entire year + self.browser['to_c'] = str(today.year) + self.browser['to_a'] = str(today.month) + self.browser['to_b'] = str(today.day) + self.browser['from_c'] = str(today.year - 1) + self.browser['from_a'] = str(today.month) + self.browser['from_b'] = str(today.day) + + # only "real" stuff, no cancelled payments + self.browser['custom_file_type'] = ['comma_completed'] + self.browser['latest_completed_file_type'] = [''] + + self.browser.submit()