From e5acc196b846bd71121c3a91bc2a8de04ccfbca0 Mon Sep 17 00:00:00 2001 From: Guillaume Risbourg Date: Thu, 7 Nov 2019 15:54:13 +0100 Subject: [PATCH] [orange] Retrieve subscriptions from api if no subscriptions found If no subscriptions were found from the 2 others _iter_subscriptions_by_type, we try to retrieve the subscriptions from the api. Closes: 12396@zendesk 13917@zendesk 14120@zendesk 14382@zendesk 14451@zendesk 14535@zendesk --- modules/orange/browser.py | 28 ++++++++++++++++++---------- modules/orange/pages/bills.py | 16 ++++++++++++++++ 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/modules/orange/browser.py b/modules/orange/browser.py index 00b975b5cb..8d64b9d213 100644 --- a/modules/orange/browser.py +++ b/modules/orange/browser.py @@ -25,7 +25,10 @@ from weboob.exceptions import BrowserIncorrectPassword, BrowserUnavailable, ActionNeeded, BrowserPasswordExpired from .pages import LoginPage, BillsPage from .pages.login import ManageCGI, HomePage, PasswordPage -from .pages.bills import SubscriptionsPage, BillsApiProPage, BillsApiParPage, ContractsPage +from .pages.bills import ( + SubscriptionsPage, SubscriptionsApiPage, BillsApiProPage, BillsApiParPage, + ContractsPage, +) from .pages.profile import ProfilePage from weboob.browser.exceptions import ClientError, ServerError from weboob.tools.compat import basestring @@ -49,6 +52,8 @@ class OrangeBillBrowser(LoginBrowser): contracts = URL(r'https://espaceclientpro.orange.fr/api/contracts\?page=1&nbcontractsbypage=15', ContractsPage) subscriptions = URL(r'https://espaceclientv3.orange.fr/js/necfe.php\?zonetype=bandeau&idPage=gt-home-page', SubscriptionsPage) + subscriptions_api = URL(r'https://sso-f.orange.fr/omoi_erb/portfoliomanager/v2.0/contractSelector/users/current', SubscriptionsApiPage) + manage_cgi = URL(r'https://eui.orange.fr/manage_eui/bin/manage.cgi', ManageCGI) # is billspage deprecated ? @@ -74,10 +79,6 @@ class OrangeBillBrowser(LoginBrowser): doc_api_pro = URL('https://espaceclientpro.orange.fr/api/contract/(?P\d+)/bill/(?P.*)/(?P.*)/\?(?P)') profile = URL('/\?page=profil-infosPerso', ProfilePage) - def __init__(self, *args, **kwargs): - super(OrangeBillBrowser, self).__init__(*args, **kwargs) - self.is_new_website = False - def do_login(self): assert isinstance(self.username, basestring) assert isinstance(self.password, basestring) @@ -97,11 +98,6 @@ def do_login(self): if error_message: raise BrowserPasswordExpired(error_message) - self.location(self.BASEURL) - print('location done / is_here : %s' % self.new_website.is_here()) - if self.new_website.is_here(): - self.is_new_website = True - def get_nb_remaining_free_sms(self): raise NotImplementedError() @@ -153,10 +149,22 @@ def get_subscription_list(self): # if nb_sub is 0, we continue, because we can get them in next url for sub in self._iter_subscriptions_by_type(profile.name, 'sosh'): + nb_sub += 1 yield sub for sub in self._iter_subscriptions_by_type(profile.name, 'orange'): + nb_sub += 1 yield sub + if nb_sub == 0: + # No subscriptions found, trying with the API. + headers = { + 'X-Orange-Caller-Id': 'ECQ', + } + self.subscriptions_api.go(headers=headers) + for sub in self.page.iter_subscription(): + sub.subscriber = profile.name + yield sub + @need_login def iter_documents(self, subscription): documents = [] diff --git a/modules/orange/pages/bills.py b/modules/orange/pages/bills.py index ec27924f1a..93dadc1f23 100644 --- a/modules/orange/pages/bills.py +++ b/modules/orange/pages/bills.py @@ -190,6 +190,22 @@ def validate(self, obj): return bool(obj.id) and obj._page != 'nec-tdb-ouvert' +class SubscriptionsApiPage(LoggedPage, JsonPage): + @method + class iter_subscription(DictElement): + item_xpath = 'contracts' + + class item(ItemElement): + klass = Subscription + + def condition(self): + return Dict('contractStatus')(self) != 'CLOS' + + obj_id = Dict('contractId') + obj_label = Dict('offerName') + obj__is_pro = False + + class ContractsPage(LoggedPage, JsonPage): @method class iter_subscriptions(DictElement): -- GitLab