Commit 886f203e authored by Florian Duguet's avatar Florian Duguet Committed by Romain Bignon

[ing] optimize download_document

ing website is stateful
store current subscription to avoid doing new request to reach the good page
each time we want to download a doc
parent e86163cf
......@@ -120,6 +120,10 @@ class IngBrowser(LoginBrowser):
self.multispace = None
self.current_space = None
# ing website is stateful, so we need to store the current subscription when download document to be sure
# we download file for the right subscription
self.current_subscription = None
def do_login(self):
assert self.password.isdigit()
assert self.birthday.isdigit()
......@@ -535,25 +539,44 @@ class IngBrowser(LoginBrowser):
if self.loginpage.is_here():
return self.billpage.go().iter_account()
subscriptions = list(self.billpage.go().iter_subscriptions())
subscriptions = list(
self.cache['subscriptions'] = {}
for sub in subscriptions:
self.cache['subscriptions'][] = sub
return subscriptions
def _go_to_subscription(self, subscription):
# ing website is not stateless, make sure we are on the correct documents page before doing anything else
if self.current_subscription and ==
def get_documents(self, subscription):
data = {"AJAXREQUEST": "_viewRoot",
"accountsel_form": "accountsel_form",
subscription._formid: subscription._formid,
"autoScroll": "",
"javax.faces.ViewState": subscription._javax,
data = {
"AJAXREQUEST": "_viewRoot",
"accountsel_form": "accountsel_form",
subscription._formid: subscription._formid,
"autoScroll": "",
"javax.faces.ViewState": subscription._javax,
self.current_subscription = subscription
def get_documents(self, subscription):
def predownload(self, bill):
def download_document(self, bill):
subid ='-')[0]
# make sure we are on the right page to not download a document from another subscription
############# CapProfile #############
......@@ -27,10 +27,9 @@ from weboob.capabilities.bill import (
SubscriptionNotFound, DocumentNotFound, DocumentTypes,
from weboob.capabilities.profile import CapProfile
from weboob.capabilities.base import find_object, NotAvailable
from weboob.capabilities.base import find_object
from import Module, BackendConfig
from import ValueBackendPassword, ValueDate
from weboob.browser.exceptions import ServerError
from .browser import IngBrowser
......@@ -138,13 +137,8 @@ class INGModule(Module, CapBankWealth, CapBankTransfer, CapDocument, CapProfile)
def download_document(self, bill):
if not isinstance(bill, Bill):
bill = self.get_document(bill)
except ServerError:
return NotAvailable
assert(self.browser.response.headers['content-type'] in ["application/pdf", "application/download"])
return self.browser.response.content
return self.browser.download_document(bill).content
def get_profile(self):
return self.browser.get_profile()
......@@ -18,7 +18,7 @@
# along with weboob. If not, see <>.
from weboob.capabilities.bill import DocumentTypes, Bill, Subscription
from weboob.browser.pages import HTMLPage, LoggedPage, pagination
from weboob.browser.pages import HTMLPage, LoggedPage, pagination, Form
from weboob.browser.filters.standard import Filter, CleanText, Format, Field, Env, Date
from weboob.browser.filters.html import Attr
from weboob.browser.elements import ListElement, ItemElement, method
......@@ -32,9 +32,18 @@ class FormId(Filter):
return formid
class MyForm(Form):
def submit(self, **kwargs):
Submit the form but keep current
return, **kwargs)
class BillsPage(LoggedPage, HTMLPage):
class iter_account(ListElement):
class iter_subscriptions(ListElement):
item_xpath = '//ul[@class="unstyled striped"]/li'
class item(ItemElement):
......@@ -45,16 +54,38 @@ class BillsPage(LoggedPage, HTMLPage):
obj_label = CleanText('label')
obj__formid = FormId(Attr('input', 'onclick'))
def postpredown(self, _id):
_id = _id.split("'")[3]
def get_selected_year(self):
return int(CleanText('//form[@id="years_form"]//ul/li[@class="rich-list-item selected"]')(self.doc))
def go_to_year(self, year):
if year == self.get_selected_year():
ref = Attr('//form[@id="years_form"]//ul//a[text()="%s"]' % year, 'id')(self.doc)
self.FORM_CLASS = Form
form = self.get_form(name="years_form")
form['AJAXREQUEST'] = 'years_form:year_region'
form[ref] = ref
return form.submit()
def download_document(self, bill):
# MyForm do open, and not location to keep html page as, to reduce number of request on this html page
self.FORM_CLASS = MyForm
_id = bill._localid.split("'")[3]
form = self.get_form(name="downpdf_form")
form['statements_form'] = 'statements_form'
form['statements_form:j_idcl'] = _id
return form.submit()
class iter_documents(ListElement):
flush_at_end = True
item_xpath = '//ul[@id="statements_form:statementsel"]/li'
def next_page(self):
......@@ -77,6 +108,10 @@ class BillsPage(LoggedPage, HTMLPage):
form[ref] = ref
return form.request
def flush(self):
for obj in reversed(self.objects.values()):
yield obj
class item(ItemElement):
klass = Bill
......@@ -89,3 +124,6 @@ class BillsPage(LoggedPage, HTMLPage):
obj_format = u"pdf"
obj_type = DocumentTypes.STATEMENT
obj__localid = Attr('a[2]', 'onclick')
def obj__year(self):
return int(CleanText('a[1]')(self).split(' ')[1])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment