diff --git a/modules/bouygues/browser.py b/modules/bouygues/browser.py index 36bc2fbae214acd83e7823a7e3e5812b39f36500..f9315c67aac671a0aa2f9e221f97009397cb5865 100644 --- a/modules/bouygues/browser.py +++ b/modules/bouygues/browser.py @@ -120,11 +120,17 @@ def iter_subscriptions(self): try: self.subscriptions_details.go(idSub=sub.id, headers=self.headers) sub.label = self.page.get_label() + sub._is_holder = self.page.is_holder() except ClientError: # if another person pay for your subscription you may not have access to this page with your credentials sub.label = phone_list if not sub.label: - sub.label = subscriber + if not sub._is_holder: + sub.label = subscriber + else: + # If the subscriber is the holder but the subscription does not have a phone number anyway + # It means that the subscription has not been activated yet + continue yield sub @need_login diff --git a/modules/bouygues/pages.py b/modules/bouygues/pages.py index 22ad07d56b0f6d0e80927af51cd3f76b8ace24ac..ddfe94cd0e586c0fc6893d7568741388cf8f9671 100644 --- a/modules/bouygues/pages.py +++ b/modules/bouygues/pages.py @@ -86,12 +86,18 @@ class item(ItemElement): class SubscriptionDetailPage(LoggedPage, JsonPage): def get_label(self): - num_tel_list = [] + label_list = [] for s in self.doc['items']: - phone = re.sub(r'^\+\d{2}', '0', s['numeroTel']) - num_tel_list.append(' '.join([phone[i:i + 2] for i in range(0, len(phone), 2)])) + if 'numeroTel' in s: + phone = re.sub(r'^\+\d{2}', '0', s['numeroTel']) + label_list.append(' '.join([phone[i:i + 2] for i in range(0, len(phone), 2)])) + else: + continue - return ' - '.join(num_tel_list) + return ' - '.join(label_list) + + def is_holder(self): + return any(CleanText(Dict('utilisateur/libelleProfilDroits'), default=None)(s) == 'Accès titulaire' for s in self.doc['items'] if 'utilisateur' in s) class SendSMSPage(HTMLPage):