diff --git a/lektor/docker/Dockerfile b/lektor/docker/Dockerfile index e1737a6..5324fab 100644 --- a/lektor/docker/Dockerfile +++ b/lektor/docker/Dockerfile @@ -8,7 +8,7 @@ RUN sed -i '/de_DE.UTF-8/s/^# //g' /etc/locale.gen && locale-gen RUN python3 -m venv /opt/venv -RUN . /opt/venv/bin/activate && pip install ics requests bs4 recurring_ical_events icalendar +RUN . /opt/venv/bin/activate && pip install requests bs4 recurring_ical_events icalendar COPY entrypoint.sh /opt/entrypoint.sh RUN chmod +x /opt/entrypoint.sh diff --git a/lektor/lektordata/scripts/calendar-fetcher-main.py b/lektor/lektordata/scripts/calendar-fetcher-main.py index 17d286f..3384397 100644 --- a/lektor/lektordata/scripts/calendar-fetcher-main.py +++ b/lektor/lektordata/scripts/calendar-fetcher-main.py @@ -1,8 +1,9 @@ from bs4 import BeautifulSoup import sys +from datetime import datetime, date +import recurring_ical_events import requests -from ics import Calendar -import arrow +from icalendar import Calendar import locale @@ -32,21 +33,41 @@ with open(sourcefile, 'r') as file: url = sys.argv[1] +locale.setlocale(locale.LC_TIME, 'de_DE.UTF-8') + #TODO: Handling HTTP request or pasring errors is currently completely missing (although I implemented such a nice handling if the script would just gracefully continue on exceptions) -c = Calendar(requests.get(url).text) +response = requests.get(url) +calendar = Calendar.from_ical(response.content) -locale.setlocale(locale.LC_TIME, locale.normalize("de_DE.UTF-8")) +# Get recurring and non-recurring events +events = recurring_ical_events.of(calendar).after(datetime.now()) -colevents = list(c.timeline.start_after(arrow.now())) +try: + event = next(events) + + + start = event.get('dtstart').dt + out_summary = event.get('summary') + location = event.get('location', 'No location specified') + + out_weekday = start.strftime("%A") + out_startdate = start.strftime("%-d. %B") + + # Format output based on whether it's an all-day event + if isinstance(start, date) and not isinstance(start, datetime): + out_starttime = "" + else: + out_starttime = start.strftime(" %-H:%M") + + if location != 'No location specified': + out_location = f" in {location}" + else: + out_location = "" + + replacestr = "