On factorise la gestion des valeurs par défaut

This commit is contained in:
Jean-Marie Favreau 2024-10-19 11:14:32 +02:00
parent 7a46bf4733
commit 58ca1a7f85
11 changed files with 27 additions and 19 deletions

View File

@ -107,14 +107,13 @@ class CExtractor(TwoStepsExtractor):
self.downloader.pause = pause
category = None
if "category" in default_values:
category = default_values["category"]
if len(categories) > 0:
category = categories[0]
for dt in datetimes:
self.add_event_with_props(
default_values,
event_url,
title,
category,

View File

@ -41,7 +41,5 @@ class CExtractor(TwoStepsExtractor):
for event in fevent.build_events(event_url):
event["published"] = published
if "category" in default_values:
event["category"] = default_values["category"]
self.add_event(**event)
self.add_event(default_values, **event)

View File

@ -93,6 +93,7 @@ class CExtractor(TwoStepsExtractor):
url_human = event_url
self.add_event_with_props(
default_values,
event_url,
None,
None,

View File

@ -68,6 +68,7 @@ class CExtractor(TwoStepsExtractor):
url_human = event_url
self.add_event_with_props(
default_values,
event_url,
title,
category,

View File

@ -76,6 +76,7 @@ class CExtractor(TwoStepsExtractor):
description = None
self.add_event_with_props(
default_values,
event_url,
title,
"Concert",

View File

@ -69,6 +69,7 @@ class CExtractor(TwoStepsExtractor):
url_human = event_url
self.add_event_with_props(
default_values,
event_url,
None,
None,

View File

@ -81,11 +81,11 @@ class CExtractor(TwoStepsExtractor):
url_human = event_url
self.add_event_with_props(
default_values,
event_url,
None,
None,
start_day,
None if "location" not in default_values else default_values["location"],
description,
None,
recurrences=None,

View File

@ -152,6 +152,7 @@ class Extractor(ABC):
def add_event(
self,
default_values,
title,
category,
start_day,
@ -176,14 +177,18 @@ class Extractor(ABC):
print("ERROR: cannot import an event without start day")
return
tags_default = self.default_value_if_exists(default_values, "tags")
if not tags_default:
tags_default = []
event = {
"title": title,
"category": category,
"category": category if category else self.default_value_if_exists(default_values, "category"),
"start_day": start_day,
"uuids": uuids,
"location": location,
"location": location if location else self.default_value_if_exists(default_values, "location"),
"description": description,
"tags": tags,
"tags": tags + tags_default,
"published": published,
"image": image,
"image_alt": image_alt,

View File

@ -278,7 +278,7 @@ class FacebookEventExtractor(Extractor):
if default_values and "category" in default_values:
event["category"] = default_values["category"]
self.add_event(**event)
self.add_event(default_values, **event)
return self.get_structure()
else:
logger.warning("cannot find any event in page")

View File

@ -19,7 +19,6 @@ class GoogleCalendarLinkEventExtractor(Extractor):
def extract(
self, content, url, url_human=None, default_values=None, published=False
):
# default_values are not used
soup = BeautifulSoup(content, "html.parser")
for ggu in self.possible_urls:
@ -41,12 +40,10 @@ class GoogleCalendarLinkEventExtractor(Extractor):
self.set_header(url)
if "category" in default_values:
category = default_values["category"]
else:
category = None
category = None
self.add_event(
default_values,
title=title,
category=category,
start_day=start_day,

View File

@ -78,7 +78,7 @@ class ICALExtractor(Extractor):
for event in calendar.walk("VEVENT"):
title = self.get_item_from_vevent(event, "SUMMARY")
category = self.default_value_if_exists(default_values, "category")
category = None
start_day, start_time = self.get_dt_item_from_vevent(event, "DTSTART")
@ -91,8 +91,8 @@ class ICALExtractor(Extractor):
end_day = end_day + timedelta(days=-1)
location = self.get_item_from_vevent(event, "LOCATION")
if location is None or location.replace(" ", "") == "":
location = self.default_value_if_exists(default_values, "location")
if location.replace(" ", "") == "":
location = None
description = self.get_item_from_vevent(event, "DESCRIPTION")
if description is not None:
@ -127,7 +127,7 @@ class ICALExtractor(Extractor):
)
# possible limitation: if the ordering is not original then related
tags = self.default_value_if_exists(default_values, "tags")
tags = None
last_modified = self.get_item_from_vevent(event, "LAST-MODIFIED", raw=True)
@ -158,6 +158,7 @@ class ICALExtractor(Extractor):
if uuidrel is not None:
luuids += [uuidrel]
self.add_event(
default_values,
title,
category,
start_day,
@ -182,6 +183,7 @@ class ICALExtractor(Extractor):
class ICALNoBusyExtractor(ICALExtractor):
def add_event(
self,
default_values,
title,
category,
start_day,
@ -201,6 +203,7 @@ class ICALNoBusyExtractor(ICALExtractor):
):
if title != "Busy" and title != "Accueils bénévoles":
super().add_event(
default_values,
title,
category,
start_day,
@ -241,6 +244,7 @@ class ICALNoVCExtractor(ICALExtractor):
def add_event(
self,
default_values,
title,
category,
start_day,
@ -259,6 +263,7 @@ class ICALNoVCExtractor(ICALExtractor):
image_alt=None,
):
super().add_event(
default_values,
title,
category,
start_day,