mirror of
https://git.bolliret.ch/pcs/pcs-website
synced 2026-01-18 11:41:38 +01:00
Reworked script for termine to use modules recurring-ical-events and icalendar for dealing with reccuring events
This commit is contained in:
parent
83c4ba2a46
commit
b25ca0df2c
2 changed files with 53 additions and 25 deletions
|
|
@ -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
|
||||
RUN . /opt/venv/bin/activate && pip install ics requests bs4 recurring_ical_events icalendar
|
||||
|
||||
COPY entrypoint.sh /opt/entrypoint.sh
|
||||
RUN chmod +x /opt/entrypoint.sh
|
||||
|
|
|
|||
|
|
@ -1,31 +1,59 @@
|
|||
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
|
||||
import sys
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: python3 {} <ICS_URL>".format(sys.argv[0]))
|
||||
def fetch_upcoming_events(ics_url):
|
||||
# Set German locale
|
||||
locale.setlocale(locale.LC_TIME, 'de_DE.UTF-8')
|
||||
|
||||
response = requests.get(ics_url)
|
||||
calendar = Calendar.from_ical(response.content)
|
||||
|
||||
# Get recurring and non-recurring events
|
||||
events = recurring_ical_events.of(calendar).after(datetime.now())
|
||||
|
||||
for event in events:
|
||||
start = event.get('dtstart').dt
|
||||
out_summary = event.get('summary')
|
||||
location = event.get('location', 'No location specified')
|
||||
|
||||
out_startdate = start.strftime("%a. %-d. %B %Y")
|
||||
|
||||
url = sys.argv[1]
|
||||
# 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 = location
|
||||
else:
|
||||
out_location = " "
|
||||
|
||||
c = Calendar(requests.get(url).text)
|
||||
print(f"* <div>{out_summary}</div> ")
|
||||
print(f" * <div>{out_startdate}</div> ")
|
||||
print(f" * <div>{out_starttime}</div> ")
|
||||
print(f" * <div>{out_location}</div> ")
|
||||
|
||||
locale.setlocale(locale.LC_TIME, locale.normalize("de_DE.UTF-8"))
|
||||
|
||||
print("_model: page")
|
||||
print("---")
|
||||
print("title: Termine")
|
||||
print("---")
|
||||
print("body:")
|
||||
print("")
|
||||
for event in list(c.timeline.start_after(arrow.now())):
|
||||
print("* <div>{}</div> ".format(event.name))
|
||||
print(" * <div>{}</div> ".format(event.begin.strftime("%a. %-d. %B %Y")))
|
||||
print(" * <div>{}</div> ".format(event.begin.strftime("%-H:%M") if not event.all_day else " "))
|
||||
print(" * <div>{}</div> ".format(event.location if event.location != None else " "))
|
||||
print("")
|
||||
print("---")
|
||||
print("_template: page.html")
|
||||
print("")
|
||||
print("")
|
||||
if __name__ == "__main__":
|
||||
|
||||
ics_url = sys.argv[1]
|
||||
|
||||
# ics_url = "https://backoffice.pc-stammertal.ch/remote.php/dav/public-calendars/RqLX5wj25aY6cpnP?export"
|
||||
|
||||
print("_model: page")
|
||||
print("---")
|
||||
print("title: Termine")
|
||||
print("---")
|
||||
print("body:")
|
||||
print("")
|
||||
fetch_upcoming_events(ics_url)
|
||||
print("")
|
||||
print("---")
|
||||
print("_template: page.html")
|
||||
print("")
|
||||
print("")
|
||||
Loading…
Add table
Reference in a new issue