From 2da48595eb263fccf366bed24fdfc1e4dbdb4263 Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Sun, 19 Jan 2025 13:38:48 +0100 Subject: [PATCH] =?UTF-8?q?Factorisation=20de=20code=20et=20ajout=20de=20l?= =?UTF-8?q?a=20d=C3=A9finition=20d'url=20dans=20les=20propri=C3=A9t=C3=A9s?= =?UTF-8?q?=20pr=C3=A9-remplies?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../import_tasks/generic_extractors.py | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/agenda_culturel/import_tasks/generic_extractors.py b/src/agenda_culturel/import_tasks/generic_extractors.py index 14acc44..d20893a 100644 --- a/src/agenda_culturel/import_tasks/generic_extractors.py +++ b/src/agenda_culturel/import_tasks/generic_extractors.py @@ -102,20 +102,22 @@ class TwoStepsExtractor(Extractor): self.event_urls.append(url) return True - def add_event_start_day(self, url, start_day): + def add_event_property(self, url, key, value): if url not in self.event_properties: self.event_properties[url] = {} - self.event_properties[url]["start_day"] = start_day + self.event_properties[url][key] = value + + def add_event_url_human(self, url, url_human): + self.add_event_property(url, "url_human", url_human) + + def add_event_start_day(self, url, start_day): + self.add_event_property(url, "start_day", start_day) def add_event_start_time(self, url, start_time): - if url not in self.event_properties: - self.event_properties[url] = {} - self.event_properties[url]["start_time"] = start_time + self.add_event_property(url, "start_time", start_time) def add_event_title(self, url, title): - if url not in self.event_properties: - self.event_properties[url] = {} - self.event_properties[url]["title"] = title + self.add_event_property(url, "title", title) def add_event_tag(self, url, tag): if url not in self.event_properties: @@ -125,14 +127,10 @@ class TwoStepsExtractor(Extractor): self.event_properties[url]["tags"].append(tag) def add_event_category(self, url, cat): - if url not in self.event_properties: - self.event_properties[url] = {} - self.event_properties[url]["category"] = cat + self.add_event_property(url, "category", cat) def add_event_location(self, url, loc): - if url not in self.event_properties: - self.event_properties[url] = {} - self.event_properties[url]["location"] = loc + self.add_event_property(url, "location", loc) def add_event_with_props( self, @@ -168,6 +166,8 @@ class TwoStepsExtractor(Extractor): category = self.event_properties[event_url]["category"] if "location" in self.event_properties[event_url]: location = self.event_properties[event_url]["location"] + if "url_human" in self.event_properties[event_url]: + url_human = self.event_properties[event_url]["url_human"] self.add_event( default_values, @@ -221,6 +221,7 @@ class TwoStepsExtractor(Extractor): self.clear_events() self.url = url + self.url_human = url_human self.event_urls = [] self.event_properties.clear()