73 lines
2.5 KiB
Python
73 lines
2.5 KiB
Python
from ..generic_extractors import *
|
|
import re
|
|
import json5
|
|
from datetime import timedelta
|
|
|
|
|
|
# A class dedicated to get events from Le Fotomat'
|
|
# URL: https://www.lefotomat.com/
|
|
class CExtractor(TwoStepsExtractor):
|
|
|
|
nom_lieu = "Le Fotomat'"
|
|
|
|
def category_fotomat2agenda(self, category):
|
|
if not category:
|
|
return None
|
|
mapping = { "Concerts": "Concert"}
|
|
if category in mapping:
|
|
return mapping[category]
|
|
else:
|
|
return None
|
|
|
|
|
|
def build_event_url_list(self, content):
|
|
soup = BeautifulSoup(content, "xml")
|
|
|
|
events = soup.select("item")
|
|
for e in events:
|
|
e_url = e.find("link").contents[0]
|
|
self.add_event_url(e_url)
|
|
|
|
title = e.find("title").contents[0]
|
|
self.add_event_title(e_url, title)
|
|
|
|
category = self.category_fotomat2agenda(e.find("category").contents[0])
|
|
if category:
|
|
self.add_event_category(e_url, category)
|
|
|
|
|
|
|
|
def add_event_from_content(self, event_content, event_url, url_human = None, default_values = None, published = False):
|
|
soup = BeautifulSoup(event_content, "html.parser")
|
|
image = soup.select("div.post-content img.wp-post-image")
|
|
if image:
|
|
image = image[0]["src"]
|
|
else:
|
|
image = None
|
|
desc = soup.select("head meta[name=description]")[0]["content"]
|
|
start_day = self.parse_french_date(desc.split("-")[0])
|
|
start_time = self.parse_french_time(desc.split("-")[1])
|
|
end_time = self.parse_french_time(desc.split("-")[2])
|
|
end_day = self.guess_end_day(start_day, start_time, end_time)
|
|
|
|
location = self.nom_lieu
|
|
descriptions = soup.select("div.vce-col-content")
|
|
if descriptions:
|
|
descriptions = [d.get_text() for d in descriptions]
|
|
description = max(descriptions, key=len)
|
|
else:
|
|
description = None
|
|
|
|
article = soup.select("article.post")
|
|
tags = []
|
|
for c in article[0]["class"]:
|
|
if c.startswith("category-"):
|
|
tag = '-'.join(c.split("-")[1:])
|
|
if tag != "concerts":
|
|
tags.append(tag)
|
|
|
|
url_human = event_url
|
|
|
|
self.add_event_with_props(event_url, None, None, start_day, location, description, tags, recurrences=None, uuids=[event_url], url_human=url_human, start_time=start_time, end_day=end_day, end_time=end_time, published=published, image=image)
|
|
|