Commit e5acc196 authored by Guillaume Risbourg's avatar Guillaume Risbourg Committed by Vincent A

[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
parent a685c04d
......@@ -25,7 +25,10 @@ from weboob.browser import LoginBrowser, URL, need_login
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<subid>\d+)/bill/(?P<dir>.*)/(?P<fact_type>.*)/\?(?P<billparams>)')
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 @@ class OrangeBillBrowser(LoginBrowser):
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 @@ class OrangeBillBrowser(LoginBrowser):
# 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 = []
......
......@@ -190,6 +190,22 @@ class SubscriptionsPage(LoggedPage, HTMLPage):
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):
......
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