from ..twosteps_extractor import *
from bs4 import BeautifulSoup
from datetime import datetime

# A class dedicated to get events from Raymond Bar
# URL: https://www.raymondbar.net/
class CExtractor(TwoStepsExtractorNoPause):

    def __init__(self):
        super().__init__()

    def build_event_url_list(self, content, infuture_days=180):
        
        soup = BeautifulSoup(content, "html.parser")

        links = soup.select(".showsList .showMore")
        if links:
            for l in links:
                print(l["href"])
                self.add_event_url(l["href"])


    def add_event_from_content(
        self,
        event_content,
        event_url,
        url_human=None,
        default_values=None,
        published=False,
    ):
        soup = BeautifulSoup(event_content, "html.parser")
        
        title = soup.select_one(".showDesc h4 a.summary").text
        start_day = soup.select_one(".showDate .value-title")
        start_time = None

        if not start_day is None:
            start_day = start_day["title"]
            if not start_day is None:
                start_day = start_day.split("T")[0]
        
        description = soup.select_one('.showDetails.description').text
        image = soup.select('.showDetails.description img')
        if not image is None:
            image_alt = image[-1]["alt"]
            image = image[-1]["src"]

        if start_time is None:
            title += " - Attention: l'heure n'a pu être extraite"

        self.add_event_with_props(
                    default_values,
                    event_url,
                    title,
                    None,
                    start_day,
                    None,
                    description,
                    [],
                    recurrences=None,
                    uuids=[event_url],
                    url_human=event_url,
                    start_time=start_time,
                    end_day=None,
                    end_time=None,
                    published=published,
                    image=image,
                    image_alt=image_alt
                )