fixing when requesting the same file
This commit is contained in:
parent
067842ef0c
commit
13802f497e
2 changed files with 28 additions and 4 deletions
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
|
|
||||||
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
|
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
|
||||||
from .pages import LoginPage, AccountPage, DownloadHistoryPage, SubmitPage, HistoryParser, UselessPage, HistoryPage
|
from .pages import LoginPage, AccountPage, DownloadHistoryPage, LastDownloadHistoryPage, SubmitPage, HistoryParser, UselessPage, HistoryPage, CSVAlreadyAsked
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -39,7 +39,9 @@ class Paypal(BaseBrowser):
|
||||||
'/cgi-bin/webscr\?cmd=_history-download&nav=0.3.1$': DownloadHistoryPage,
|
'/cgi-bin/webscr\?cmd=_history-download&nav=0.3.1$': DownloadHistoryPage,
|
||||||
'/cgi-bin/webscr\?cmd=_history&nav=0.3.0$': HistoryPage,
|
'/cgi-bin/webscr\?cmd=_history&nav=0.3.0$': HistoryPage,
|
||||||
'/cgi-bin/webscr\?cmd=_history&dispatch=[a-z0-9]+$': HistoryPage,
|
'/cgi-bin/webscr\?cmd=_history&dispatch=[a-z0-9]+$': HistoryPage,
|
||||||
|
'/cgi-bin/webscr\?cmd=_history-download-recent$': LastDownloadHistoryPage,
|
||||||
'/cgi-bin/webscr\?dispatch=[a-z0-9]+$': (SubmitPage, HistoryParser()),
|
'/cgi-bin/webscr\?dispatch=[a-z0-9]+$': (SubmitPage, HistoryParser()),
|
||||||
|
'/cgi-bin/webscr\?cmd=_history-download-recent-submit&dispatch=[a-z0-9]+$': (SubmitPage, HistoryParser()),
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFAULT_TIMEOUT = 30 # CSV export is slow
|
DEFAULT_TIMEOUT = 30 # CSV export is slow
|
||||||
|
|
@ -104,11 +106,16 @@ class Paypal(BaseBrowser):
|
||||||
if self.download_history(start, end).rows:
|
if self.download_history(start, end).rows:
|
||||||
return self.page.iter_transactions(account)
|
return self.page.iter_transactions(account)
|
||||||
assert step_max <= 365*2 # PayPal limitations as of 2014-06-16
|
assert step_max <= 365*2 # PayPal limitations as of 2014-06-16
|
||||||
return self.smart_fetch(beginning=self.BEGINNING,
|
try:
|
||||||
|
for i in self.smart_fetch(beginning=self.BEGINNING,
|
||||||
end=datetime.date.today(),
|
end=datetime.date.today(),
|
||||||
step_min=step_min,
|
step_min=step_min,
|
||||||
step_max=step_max,
|
step_max=step_max,
|
||||||
fetch_fn=fetch_fn)
|
fetch_fn=fetch_fn):
|
||||||
|
yield i
|
||||||
|
except CSVAlreadyAsked:
|
||||||
|
for i in self.download_last_history(account):
|
||||||
|
yield i
|
||||||
|
|
||||||
def smart_fetch(self, beginning, end, step_min, step_max, fetch_fn):
|
def smart_fetch(self, beginning, end, step_min, step_max, fetch_fn):
|
||||||
"""
|
"""
|
||||||
|
|
@ -144,5 +151,11 @@ class Paypal(BaseBrowser):
|
||||||
assert self.is_on_page(SubmitPage)
|
assert self.is_on_page(SubmitPage)
|
||||||
return self.page.document
|
return self.page.document
|
||||||
|
|
||||||
|
def download_last_history(self, account):
|
||||||
|
self.location('/en/cgi-bin/webscr?cmd=_history-download-recent')
|
||||||
|
self.page.download()
|
||||||
|
if self.page.document.rows:
|
||||||
|
return self.page.iter_transactions(account)
|
||||||
|
|
||||||
def transfer(self, from_id, to_id, amount, reason=None):
|
def transfer(self, from_id, to_id, amount, reason=None):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,10 @@ from weboob.tools.misc import to_unicode
|
||||||
from weboob.capabilities.bank import Account, Transaction
|
from weboob.capabilities.bank import Account, Transaction
|
||||||
from weboob.tools.capabilities.bank.transactions import FrenchTransaction
|
from weboob.tools.capabilities.bank.transactions import FrenchTransaction
|
||||||
|
|
||||||
__all__ = ['LoginPage', 'AccountPage']
|
__all__ = ['LoginPage', 'AccountPage', 'LastDownloadHistoryPage']
|
||||||
|
|
||||||
|
class CSVAlreadyAsked(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
def clean_amount(text):
|
def clean_amount(text):
|
||||||
"""
|
"""
|
||||||
|
|
@ -126,6 +128,9 @@ class AccountPage(BasePage):
|
||||||
|
|
||||||
class DownloadHistoryPage(BasePage):
|
class DownloadHistoryPage(BasePage):
|
||||||
def download(self, start, end):
|
def download(self, start, end):
|
||||||
|
last_file_request = self.document.xpath('//table//table//table//tr[2]//td')[1].text[:-1]
|
||||||
|
if dateutil.parser.parse(last_file_request).date() == datetime.date.today():
|
||||||
|
raise CSVAlreadyAsked('')
|
||||||
self.browser.select_form(name='form1')
|
self.browser.select_form(name='form1')
|
||||||
self.browser['to_c'] = str(end.year)
|
self.browser['to_c'] = str(end.year)
|
||||||
self.browser['to_a'] = str(end.month)
|
self.browser['to_a'] = str(end.month)
|
||||||
|
|
@ -139,6 +144,12 @@ class DownloadHistoryPage(BasePage):
|
||||||
|
|
||||||
self.browser.submit()
|
self.browser.submit()
|
||||||
|
|
||||||
|
class LastDownloadHistoryPage(BasePage):
|
||||||
|
def download(self):
|
||||||
|
self.browser.select_form(nr=1)
|
||||||
|
log_select = self.document.xpath('//table//form//input[@type="radio"]')[0].attrib['value']
|
||||||
|
self.browser['log_select'] = [log_select]
|
||||||
|
self.browser.submit()
|
||||||
|
|
||||||
class SubmitPage(BasePage):
|
class SubmitPage(BasePage):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue