From 9475c99e0f24480b6da0275b22718d9f23a392ab Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Fri, 21 Feb 2025 16:13:54 +0100 Subject: [PATCH] =?UTF-8?q?On=20am=C3=A9liore=20la=20gestion=20du=20debug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../custom_extractors/fbevents.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/agenda_culturel/import_tasks/custom_extractors/fbevents.py b/src/agenda_culturel/import_tasks/custom_extractors/fbevents.py index 424b00c..18a558d 100644 --- a/src/agenda_culturel/import_tasks/custom_extractors/fbevents.py +++ b/src/agenda_culturel/import_tasks/custom_extractors/fbevents.py @@ -52,7 +52,7 @@ class CExtractor(TwoStepsExtractor): def build_event_url_list(self, content): soup = BeautifulSoup(content, "html.parser") - debug = False + debug = True self.found = False links = soup.find_all("a") @@ -65,22 +65,24 @@ class CExtractor(TwoStepsExtractor): self.has_page_items = False self.find_in_js(soup) + + if not self.found: + logger.warning("cannot find any event link in events page. Save content page") + if debug: + CExtractor.dump_content_for_debug(content, self.url) + if not self.has_page_items: raise Exception(_("the page was not yet populated with events, so the loading time was probably too short")) - if not self.found and debug: - logger.warning("cannot find any event link in events page. Save content page in " + filename) - self.dump_content_for_debug(content) - - def dump_content_for_debug(self, content): + def dump_content_for_debug(content, url): directory = "errors/" if not os.path.exists(directory): os.makedirs(directory) now = datetime.now() filename = directory + now.strftime("%Y%m%d_%H%M%S") + ".html" with open(filename, "w") as text_file: - text_file.write("\n\n") + text_file.write("\n\n") text_file.write(content) @@ -111,7 +113,8 @@ class CExtractor(TwoStepsExtractor): self.add_event(default_values, **event) else: - self.dump_content_for_debug(event_content) + if debug: + CExtractor.dump_content_for_debug(event_content, event_url) raise Exception( _("Cannot get Facebook event from {}").format(event_url) )