From cbad97f351bb46745c91f7544800f5bb5dde7542 Mon Sep 17 00:00:00 2001 From: Romain Pesche Date: Mon, 16 Dec 2019 15:05:40 +0100 Subject: [PATCH] [bouygues] create label from sub id and phone numbers Sometimes there is no phone numbers associated to a subscription. In this case the label was empty like " - " We now use the subscription id as label, and concat phone numbers list to it if we can get them. --- modules/bouygues/browser.py | 3 ++- modules/bouygues/pages.py | 25 +++++++++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/modules/bouygues/browser.py b/modules/bouygues/browser.py index 639798ab6f..5625fb5fd2 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 b9aec40747..8d834fbf99 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')) -- GitLab