Première version fonctionnelle de l'import d'événements

This commit is contained in:
Jean-Marie Favreau
2023-12-29 16:56:38 +01:00
parent 07729353ae
commit bec3fef0bf
17 changed files with 650 additions and 137 deletions

View File

@@ -12,6 +12,7 @@ from selenium.webdriver.chrome.options import Options
import icalendar
from datetime import datetime, date
import json
from bs4 import BeautifulSoup
@@ -76,7 +77,7 @@ class Extractor(ABC):
def clear_events(self):
self.events = []
def add_event(self, title, category, start_day, location, description, tags, url=None, url_human=None, start_time=None, end_day=None, end_time=None, last_modified=None, published=False):
def add_event(self, title, category, start_day, location, description, tags, uuid, url_human=None, start_time=None, end_day=None, end_time=None, last_modified=None, published=False):
if title is None:
print("ERROR: cannot import an event without name")
return
@@ -88,13 +89,12 @@ class Extractor(ABC):
"title": title,
"category": category,
"start_day": start_day,
"uuid": uuid,
"location": location,
"descritpion": description,
"description": description,
"tags": tags,
"published": published
}
if url is not None:
event["url"] = url
if url_human is not None:
event["url_human"] = url_human
if start_time is not None:
@@ -167,6 +167,12 @@ class ICALExtractor(Extractor):
location = self.default_value_if_exists(default_values, "location")
description = self.get_item_from_vevent(event, "DESCRIPTION")
if description is not None:
soup = BeautifulSoup(description)
delimiter = '\n'
for line_break in soup.findAll('br'):
line_break.replaceWith(delimiter)
description = soup.get_text()
last_modified = self.get_item_from_vevent(event, "LAST_MODIFIED")
@@ -183,7 +189,7 @@ class ICALExtractor(Extractor):
if rrule is not None:
print("Recurrent event not yet supported", rrule)
self.add_event(title, category, start_day, location, description, tags, url=event_url, url_human=url_human, start_time=start_time, end_day=end_day, end_time=end_time, last_modified=last_modified, published=published)
self.add_event(title, category, start_day, location, description, tags, uuid=event_url, url_human=url_human, start_time=start_time, end_day=end_day, end_time=end_time, last_modified=last_modified, published=published)
return self.get_structure()