From 332d59d8f652fb813bae637bac258b5ed15a5bb8 Mon Sep 17 00:00:00 2001 From: Florian Duguet Date: Thu, 20 Jun 2019 16:42:34 +0200 Subject: [PATCH] [orange] update bill page for par website Closes: 34908@sibi --- modules/orange/browser.py | 17 +++++++++++------ modules/orange/module.py | 4 ++++ modules/orange/pages/bills.py | 32 +++++++++++++++++++++++++++++--- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/modules/orange/browser.py b/modules/orange/browser.py index fc942b5601..7c583ef61b 100644 --- a/modules/orange/browser.py +++ b/modules/orange/browser.py @@ -25,7 +25,7 @@ from weboob.exceptions import BrowserIncorrectPassword, BrowserUnavailable, ActionNeeded from .pages import LoginPage, BillsPage from .pages.login import ManageCGI, HomePage -from .pages.bills import SubscriptionsPage, BillsApiPage, ContractsPage +from .pages.bills import SubscriptionsPage, BillsApiProPage, BillsApiParPage, ContractsPage from .pages.profile import ProfilePage from weboob.browser.exceptions import ClientError, ServerError from weboob.tools.compat import basestring @@ -47,6 +47,7 @@ class OrangeBillBrowser(LoginBrowser): subscriptions = URL(r'https://espaceclientv3.orange.fr/js/necfe.php\?zonetype=bandeau&idPage=gt-home-page', SubscriptionsPage) manage_cgi = URL('https://eui.orange.fr/manage_eui/bin/manage.cgi', ManageCGI) + # is billspage deprecated ? billspage = URL('https://m.espaceclientv3.orange.fr/\?page=factures-archives', 'https://.*.espaceclientv3.orange.fr/\?page=factures-archives', 'https://espaceclientv3.orange.fr/\?page=factures-archives', @@ -56,10 +57,13 @@ class OrangeBillBrowser(LoginBrowser): 'https://espaceclientv3.orange.fr/\?page=factures-historique&idContrat=(?P.*)', BillsPage) - bills_api = URL('https://espaceclientpro.orange.fr/api/contract/(?P\d+)/bills\?count=(?P)', - BillsApiPage) + bills_api_pro = URL('https://espaceclientpro.orange.fr/api/contract/(?P\d+)/bills\?count=(?P)', + BillsApiProPage) - doc_api = URL('https://espaceclientpro.orange.fr/api/contract/(?P\d+)/bill/(?P.*)/(?P.*)/\?(?P)') + bills_api_par = URL(r'https://sso-f.orange.fr/omoi_erb/facture/v2.0/billsAndPaymentInfos/users/current/contracts/(?P\d+)', BillsApiParPage) + doc_api_par = URL(r'https://sso-f.orange.fr/omoi_erb/facture/v1.0/pdf') + + doc_api_pro = URL('https://espaceclientpro.orange.fr/api/contract/(?P\d+)/bill/(?P.*)/(?P.*)/\?(?P)') profile = URL('/\?page=profil-infosPerso', ProfilePage) def do_login(self): @@ -132,12 +136,13 @@ def get_subscription_list(self): def iter_documents(self, subscription): documents = [] if subscription._is_pro: - for d in self.bills_api.go(subid=subscription.id, count=72).get_bills(subid=subscription.id): + for d in self.bills_api_pro.go(subid=subscription.id, count=72).get_bills(subid=subscription.id): documents.append(d) # check pagination for this subscription assert len(documents) != 72 else: - self.billspage.go(subid=subscription.id) + headers = {'x-orange-caller-id': 'ECQ'} + self.bills_api_par.go(subid=subscription.id, headers=headers) for b in self.page.get_bills(subid=subscription.id): documents.append(b) return iter(documents) diff --git a/modules/orange/module.py b/modules/orange/module.py index 66ee0473bb..cae6b51336 100644 --- a/modules/orange/module.py +++ b/modules/orange/module.py @@ -72,6 +72,10 @@ def download_document(self, document): document = self.get_document(document) if document.url is NotAvailable: return + + if document._is_v2: + # get 404 without this header + return self.browser.open(document.url, headers={'x-orange-caller-id': 'ECQ'}).content return self.browser.open(document.url).content def get_profile(self): diff --git a/modules/orange/pages/bills.py b/modules/orange/pages/bills.py index d9cc37c47e..89a4eeb90c 100644 --- a/modules/orange/pages/bills.py +++ b/modules/orange/pages/bills.py @@ -28,7 +28,9 @@ from weboob.browser.pages import HTMLPage, LoggedPage, JsonPage from weboob.capabilities.bill import Subscription from weboob.browser.elements import DictElement, ListElement, ItemElement, method, TableElement -from weboob.browser.filters.standard import CleanDecimal, CleanText, Env, Field, Regexp, Date, Currency, BrowserURL, Format +from weboob.browser.filters.standard import ( + CleanDecimal, CleanText, Env, Field, Regexp, Date, Currency, BrowserURL, Format, Eval +) from weboob.browser.filters.html import Link, TableCell from weboob.browser.filters.javascript import JSValue from weboob.browser.filters.json import Dict @@ -38,7 +40,7 @@ from weboob.tools.compat import urlencode -class BillsApiPage(LoggedPage, JsonPage): +class BillsApiProPage(LoggedPage, JsonPage): @method class get_bills(DictElement): item_xpath = 'bills' @@ -64,9 +66,33 @@ def get_params(self): params = {'billid': Dict('id')(self), 'billDate': Dict('dueDate')(self)} return urlencode(params) - obj_url = BrowserURL('doc_api', subid=Env('subid'), dir=Dict('documents/0/mainDir'), fact_type=Dict('documents/0/subDir'), billparams=get_params) + obj_url = BrowserURL('doc_api_pro', subid=Env('subid'), dir=Dict('documents/0/mainDir'), fact_type=Dict('documents/0/subDir'), billparams=get_params) + obj__is_v2 = False +class BillsApiParPage(LoggedPage, JsonPage): + @method + class get_bills(DictElement): + item_xpath = 'billsHistory/billList' + + class item(ItemElement): + klass = Bill + + obj_date = Date(Dict('date'), default=NotAvailable) + obj_price = Eval(lambda x: x / 100, CleanDecimal(Dict('amount'))) + obj_format = 'pdf' + + def obj_label(self): + return 'Facture du %s' % Field('date')(self) + + def obj_id(self): + return '%s_%s' % (Env('subid')(self), Field('date')(self).strftime('%d%m%Y')) + + obj_url = Format('%s%s', BrowserURL('doc_api_par'), Dict('hrefPdf')) + obj__is_v2 = True + + +# is BillsPage deprecated ? class BillsPage(LoggedPage, HTMLPage): @method class get_bills(TableElement): -- GitLab