Ajout d'un mécanisme de warning pour les heures mal détectées

Fix #413
This commit is contained in:
Jean-Marie Favreau 2025-04-26 11:30:58 +02:00
parent 573584cf43
commit 62688539e7
5 changed files with 516 additions and 464 deletions

View File

@ -377,6 +377,13 @@ class DBImporterEvents:
+ ": " + ": "
+ _("the date has not been imported correctly.") + _("the date has not been imported correctly.")
) )
if w == Extractor.Warning.NO_START_TIME:
event_structure["title"] += (
" - "
+ _("Warning")
+ ": "
+ _("the time has not been imported correctly.")
)
if "category" in event_structure and event_structure["category"] is not None: if "category" in event_structure and event_structure["category"] is not None:
try: try:
@ -485,6 +492,16 @@ class DBImporterEvents:
message_type=Message.TYPE.WARNING, message_type=Message.TYPE.WARNING,
) )
) )
if w == Extractor.Warning.NO_START_TIME:
result.set_invalid_start_time()
result.add_message(
Message(
subject=_("warning"),
closed=False,
message=_("the time has not been imported correctly."),
message_type=Message.TYPE.WARNING,
)
)
if w == Extractor.Warning.NO_TITLE: if w == Extractor.Warning.NO_TITLE:
result.set_invalid_title() result.set_invalid_title()
result.add_message( result.add_message(

View File

@ -29,7 +29,7 @@ class CExtractor(TwoStepsExtractorNoPause):
title = soup.select_one(".showDesc h4 a.summary").text title = soup.select_one(".showDesc h4 a.summary").text
start_day = soup.select_one(".showDate .value-title") start_day = soup.select_one(".showDate .value-title")
start_time = None start_time = "warning"
if start_day is not None: if start_day is not None:
start_day = start_day["title"] start_day = start_day["title"]
@ -45,9 +45,6 @@ class CExtractor(TwoStepsExtractorNoPause):
image = None image = None
image_alt = None image_alt = None
if start_time is None:
title += " - Attention: l'heure n'a pu être extraite"
self.add_event_with_props( self.add_event_with_props(
default_values, default_values,
event_url, event_url,

View File

@ -12,7 +12,8 @@ class Extractor(ABC):
class Warning(IntEnum): class Warning(IntEnum):
NO_TITLE = 1 NO_TITLE = 1
NO_START_DATE = 2 NO_START_DATE = 2
NOT_FOUND = 3 NO_START_TIME = 3
NOT_FOUND = 4
url_referer = None url_referer = None
@ -229,6 +230,11 @@ class Extractor(ABC):
published = False published = False
start_day = datetime.now().date().strftime("%Y-%m-%d") start_day = datetime.now().date().strftime("%Y-%m-%d")
warnings.append(Extractor.Warning.NO_START_DATE) warnings.append(Extractor.Warning.NO_START_DATE)
if isinstance(start_time, str):
print("WARNING: start time was not found")
published = False
start_time = None
warnings.append(Extractor.Warning.NO_START_TIME)
if not_found: if not_found:
warnings.append(Extractor.Warning.NOT_FOUND) warnings.append(Extractor.Warning.NOT_FOUND)

File diff suppressed because it is too large Load Diff

View File

@ -1595,6 +1595,12 @@ class Event(models.Model):
def is_in_moderation_process(self): def is_in_moderation_process(self):
return hasattr(self, "in_moderation_process") return hasattr(self, "in_moderation_process")
def set_invalid_start_time(self):
self.invalid_start_time = True
def has_invalid_start_time(self):
return hasattr(self, "invalid_start_time")
def set_invalid_start_date(self): def set_invalid_start_date(self):
self.invalid_start_date = True self.invalid_start_date = True
@ -2040,6 +2046,10 @@ class Event(models.Model):
self.has_invalid_start_date() or event.has_invalid_start_date() self.has_invalid_start_date() or event.has_invalid_start_date()
): ):
continue continue
if r["key"] == "start_time" and (
self.has_invalid_start_time() or event.has_invalid_start_time()
):
continue
return False return False
return True return True
@ -2122,7 +2132,12 @@ class Event(models.Model):
self.organisers.set(other.pending_organisers) self.organisers.set(other.pending_organisers)
logger.info( logger.info(
"process update " + other.title + " " + str(other.has_invalid_start_date()) "process update "
+ other.title
+ " "
+ str(other.has_invalid_start_date())
+ " "
+ str(other.has_invalid_start_time())
) )
# set attributes # set attributes
for attr in Event.data_fields(all=all, no_m2m=True): for attr in Event.data_fields(all=all, no_m2m=True):
@ -2130,6 +2145,8 @@ class Event(models.Model):
continue continue
if attr == "start_day" and other.has_invalid_start_date(): if attr == "start_day" and other.has_invalid_start_date():
continue continue
if attr == "start_time" and other.has_invalid_start_time():
continue
if attr == "exact_location" and other.exact_location is None: if attr == "exact_location" and other.exact_location is None:
continue continue
setattr(self, attr, getattr(other, attr)) setattr(self, attr, getattr(other, attr))