The new woob repository is here: https://gitlab.com/woob/woob. This gitlab will be removed soon.

The new woob repository is here: https://gitlab.com/woob/woob. This gitlab will be removed soon.

Commit 613d5083 authored by Christophe François's avatar Christophe François Committed by Vincent A

[axabanque] Handle undownloadable documents and downloads with a URL

Some documents are not downloadable with the usual URL (which uses the
`download_id` as a parameter) but with a specific URL which can be
fetched from the detail page.

Other documents are not downloadable and the link leads to a page with a
form to be sent the document by mail (not email, mail).

Finally, the URL for contracts has changed, and some documents have no
date.
parent 0a60969d
......@@ -56,7 +56,7 @@
ConfirmTransferPage, RecipientConfirmationPage, ScheduledTransfersPage,
ScheduledTransferDetailsPage,
)
from .pages.document import DocumentsPage, DownloadPage
from .pages.document import DocumentsPage, DownloadPage, DocumentDetailsPage
class AXABrowser(LoginBrowser):
......@@ -789,7 +789,7 @@ class AXAAssurance(AXABrowser):
performance_monaxa = URL(r'https://monaxaweb-gp.axa.fr/MonAxa/ContratPerformance/', PerformanceMonAxaPage)
documents_life_insurance = URL(
r'/content/espace-client/accueil/mes-documents/situations-de-contrats-assurance-vie.content-inner.din_SAVINGS_STATEMENT.html',
r'/content/espace-client/accueil/mes-documents/contrats.content-inner.din_POLICY.html',
DocumentsPage
)
documents_certificates = URL(
......@@ -804,9 +804,13 @@ class AXAAssurance(AXABrowser):
r'/content/espace-client/accueil/mes-documents/avis-d-echeance.content-inner.din_PREMIUM_STATEMENT.html',
DocumentsPage
)
document_details = URL(
r'/content/ecc-popin-cards/technical/detailed/dam-document.content-inner',
DocumentDetailsPage
)
download = URL(
r'/content/ecc-popin-cards/technical/detailed/download-document.downloadPdf.html',
r'/content/dam/axa/ecc/pdf',
DownloadPage
)
profile = URL(r'/content/ecc-popin-cards/transverse/userprofile.content-inner.html\?_=\d+', ProfilePage)
......@@ -943,9 +947,20 @@ def iter_documents(self, subscription):
yield doc
@need_login
def download_document(self, download_id):
self.download.go(data={'documentId': download_id})
return self.page.content
def download_document(self, document):
# "On request" documents are not downloadable, they are sent by physical mail
if 'onrequest-document' in document.url:
return
# These documents have a direct download URL instead of a download ID.
elif 'dam-document' in document.url:
self.location(document.url)
document_url = self.page.get_download_url()
self.location(document_url)
return self.page.content
# These documents are obtained with a generic URL and a download ID as a parameter.
elif document._download_id:
self.download.go(data={'documentId': document._download_id})
return self.page.content
@need_login
def get_profile(self):
......
......@@ -170,7 +170,7 @@ def iter_documents(self, subscription):
def download_document(self, document):
if not isinstance(document, Document):
document = self.get_document(document)
return self.browser.download_document(document._download_id)
return self.browser.download_document(document)
def iter_resources(self, objs, split_path):
if Account in objs:
......
......@@ -20,8 +20,10 @@
from __future__ import unicode_literals
from woob.browser.pages import HTMLPage, LoggedPage
from woob.browser.filters.html import Attr
from woob.browser.filters.standard import CleanText, Env, Regexp, Format, Date
from woob.browser.elements import ListElement, ItemElement, method
from woob.capabilities import NotAvailable
from woob.capabilities.bill import Document
from woob.tools.date import parse_french_date
......@@ -37,7 +39,7 @@ class item(ItemElement):
obj_id = Format(
'%s_%s',
Env('subid'),
Regexp(CleanText('./@data-module-open-link--link'), '#/details/(.*)'),
Regexp(Attr('.', 'data-module-open-link--link'), r'#/details/(.*)'),
)
obj_format = 'pdf'
# eg when formatted (not complete list):
......@@ -50,12 +52,18 @@ class item(ItemElement):
CleanText('.//div[@class="sticker-content"]//strong'),
CleanText('.//p[@class="contract-info"]'),
)
obj_date = Date(CleanText('.//p[@class="card-date"]'), parse_func=parse_french_date)
obj_date = Date(CleanText('.//p[@class="card-date"]'), parse_func=parse_french_date, default=NotAvailable)
obj_type = 'document'
obj__download_id = Regexp(CleanText('./@data-url'), r'.did_(.*?)\.')
obj_url = Attr('.', 'data-url')
obj__download_id = Regexp(Attr('.', 'data-url'), r'.[dp]id_(.*?)\.', default=None)
class DownloadPage(LoggedPage, HTMLPage):
def create_document(self):
form = self.get_form(xpath='//form[has-class("form-download-pdf")]')
form.submit()
class DocumentDetailsPage(LoggedPage, HTMLPage):
def get_download_url(self):
return Attr('//button', 'data-module-open-link--link')(self.doc)
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