diff --git a/modules/bouygues/browser.py b/modules/bouygues/browser.py index 639798ab6ff7979ea0e1ff281706ea71f664e6ff..5625fb5fd2805548f7a2a7a1ba5b6744f7c26a27 100644 --- a/modules/bouygues/browser.py +++ b/modules/bouygues/browser.py @@ -120,4 +120,5 @@ def iter_documents(self, subscription): @need_login def download_document(self, document): - return self.location(document.url, headers=self.headers).content + if document.url: + return self.location(document.url, headers=self.headers).content diff --git a/modules/bouygues/pages.py b/modules/bouygues/pages.py index b9aec40747a224205944dabe2b12925706e00074..8d834fbf99ff62f2be4968432e2195cebe11723b 100644 --- a/modules/bouygues/pages.py +++ b/modules/bouygues/pages.py @@ -66,20 +66,26 @@ def get_subscriber(self): elif self.doc['type'] == 'ENTREPRISE': subscriber_dict = self.doc['representantLegal'] - return '%s %s %s' % (subscriber_dict['civilite'], subscriber_dict['prenom'], subscriber_dict['nom']) + subscriber = '%s %s %s' % (subscriber_dict.get('civilite', ''), subscriber_dict['prenom'], subscriber_dict['nom']) + return subscriber.strip() class SubscriptionDetail(LoggedPage, JsonPage): def get_label(self): - label_list = [] + phone_numbers = list(self.get_phone_numbers()) + account_id = self.params['id_account'] + + label = str(account_id) + + if phone_numbers: + label += " ({})".format(" - ".join(phone_numbers)) + return label + + def get_phone_numbers(self): for s in self.doc['items']: 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(label_list) + yield ' '.join([phone[i:i + 2] for i in range(0, len(phone), 2)]) class SubscriptionPage(LoggedPage, JsonPage): @@ -117,7 +123,10 @@ class item(ItemElement): obj_id = Format('%s_%s', Env('subid'), Dict('idFacture')) obj_price = CleanDecimal(Dict('mntTotFacture')) - obj_url = Coalesce(Dict('_links/facturePDF/href', default=NotAvailable), Dict('_links/facturePDFDF/href', default=NotAvailable)) + obj_url = Coalesce( + Dict('_links/facturePDF/href', default=NotAvailable), + Dict('_links/facturePDFDF/href', default=NotAvailable) + ) obj_date = MyDate(Dict('dateFacturation')) obj_duedate = MyDate(Dict('dateLimitePaieFacture', default=NotAvailable), default=NotAvailable) obj_label = Format('Facture %s', Dict('idFacture'))