mirror of
https://git.bolliret.ch/pcs/pcs-website
synced 2026-01-18 20:41:38 +01:00
Compare commits
No commits in common. "73cee8a6532da88e59dfa6bbab9bcdec36f1bdde" and "83c4ba2a464dd0468b33abb533d6b9b850ce9e46" have entirely different histories.
73cee8a653
...
83c4ba2a46
3 changed files with 39 additions and 89 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 python3 -m venv /opt/venv
|
||||||
|
|
||||||
RUN . /opt/venv/bin/activate && pip install requests bs4 recurring_ical_events icalendar
|
RUN . /opt/venv/bin/activate && pip install ics requests bs4
|
||||||
|
|
||||||
COPY entrypoint.sh /opt/entrypoint.sh
|
COPY entrypoint.sh /opt/entrypoint.sh
|
||||||
RUN chmod +x /opt/entrypoint.sh
|
RUN chmod +x /opt/entrypoint.sh
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import sys
|
import sys
|
||||||
from datetime import datetime, date
|
|
||||||
import recurring_ical_events
|
|
||||||
import requests
|
import requests
|
||||||
from icalendar import Calendar
|
from ics import Calendar
|
||||||
|
import arrow
|
||||||
import locale
|
import locale
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -33,41 +32,21 @@ with open(sourcefile, 'r') as file:
|
||||||
|
|
||||||
url = sys.argv[1]
|
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)
|
#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)
|
||||||
response = requests.get(url)
|
c = Calendar(requests.get(url).text)
|
||||||
calendar = Calendar.from_ical(response.content)
|
|
||||||
|
|
||||||
# Get recurring and non-recurring events
|
locale.setlocale(locale.LC_TIME, locale.normalize("de_DE.UTF-8"))
|
||||||
events = recurring_ical_events.of(calendar).after(datetime.now())
|
|
||||||
|
|
||||||
try:
|
colevents = list(c.timeline.start_after(arrow.now()))
|
||||||
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", {location}"
|
|
||||||
else:
|
|
||||||
out_location = ""
|
|
||||||
|
|
||||||
replacestr = "<div class=\"nextevent\">{} <strong> {}{}, {}</strong>{}</div>".format(out_weekday, out_startdate, out_starttime, out_summary, out_location)
|
|
||||||
|
|
||||||
except StopIteration:
|
|
||||||
|
|
||||||
|
if len(colevents) > 0 :
|
||||||
|
weekday = colevents[0].begin.strftime("%A")
|
||||||
|
date = colevents[0].begin.strftime("%-d. %B")
|
||||||
|
time = colevents[0].begin.strftime(" %-H:%M") if not colevents[0].all_day else ""
|
||||||
|
name = colevents[0].name
|
||||||
|
location = " in " + colevents[0].location if colevents[0].location != None else ""
|
||||||
|
replacestr = "<div class=\"nextevent\">{} <strong> {}{}, {}</strong>{}</div>".format(weekday, date, time, name, location)
|
||||||
|
else:
|
||||||
replacestr = fallbackreplacestr
|
replacestr = fallbackreplacestr
|
||||||
|
|
||||||
# Why should we check if sourcestring is in the file when it originates from there?!?
|
# Why should we check if sourcestring is in the file when it originates from there?!?
|
||||||
|
|
@ -76,7 +55,6 @@ except StopIteration:
|
||||||
# Also an empty string is a perfect match and matches in the wrong place, therefore we check for a minimal length > 0
|
# Also an empty string is a perfect match and matches in the wrong place, therefore we check for a minimal length > 0
|
||||||
# TODO: Most probably replacement could be done by BeautifulSoup too.
|
# TODO: Most probably replacement could be done by BeautifulSoup too.
|
||||||
# But as this is a collection of StackOverflow roadkill rather than fine crafted menu of purest python ingredients, that's just what I could catch most easily.
|
# But as this is a collection of StackOverflow roadkill rather than fine crafted menu of purest python ingredients, that's just what I could catch most easily.
|
||||||
|
|
||||||
if len(sourcestr) > 0 and sourcestr in file_contents:
|
if len(sourcestr) > 0 and sourcestr in file_contents:
|
||||||
|
|
||||||
updated_contents = file_contents.replace(sourcestr, replacestr)
|
updated_contents = file_contents.replace(sourcestr, replacestr)
|
||||||
|
|
|
||||||
|
|
@ -1,59 +1,31 @@
|
||||||
from datetime import datetime, date
|
|
||||||
import recurring_ical_events
|
|
||||||
import requests
|
|
||||||
from icalendar import Calendar
|
|
||||||
import locale
|
|
||||||
import sys
|
import sys
|
||||||
|
import requests
|
||||||
|
from ics import Calendar
|
||||||
|
import arrow
|
||||||
|
import locale
|
||||||
|
|
||||||
def fetch_upcoming_events(ics_url):
|
if len(sys.argv) != 2:
|
||||||
# Set German locale
|
print("Usage: python3 {} <ICS_URL>".format(sys.argv[0]))
|
||||||
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")
|
|
||||||
|
|
||||||
# Format output based on whether it's an all-day event
|
url = sys.argv[1]
|
||||||
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 = " "
|
|
||||||
|
|
||||||
print(f"* <div>{out_summary}</div> ")
|
c = Calendar(requests.get(url).text)
|
||||||
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"))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
print("_model: page")
|
||||||
|
print("---")
|
||||||
ics_url = sys.argv[1]
|
print("title: Termine")
|
||||||
|
print("---")
|
||||||
# ics_url = "https://backoffice.pc-stammertal.ch/remote.php/dav/public-calendars/RqLX5wj25aY6cpnP?export"
|
print("body:")
|
||||||
|
print("")
|
||||||
print("_model: page")
|
for event in list(c.timeline.start_after(arrow.now())):
|
||||||
print("---")
|
print("* <div>{}</div> ".format(event.name))
|
||||||
print("title: Termine")
|
print(" * <div>{}</div> ".format(event.begin.strftime("%a. %-d. %B %Y")))
|
||||||
print("---")
|
print(" * <div>{}</div> ".format(event.begin.strftime("%-H:%M") if not event.all_day else " "))
|
||||||
print("body:")
|
print(" * <div>{}</div> ".format(event.location if event.location != None else " "))
|
||||||
print("")
|
print("")
|
||||||
fetch_upcoming_events(ics_url)
|
print("---")
|
||||||
print("")
|
print("_template: page.html")
|
||||||
print("---")
|
print("")
|
||||||
print("_template: page.html")
|
print("")
|
||||||
print("")
|
|
||||||
print("")
|
|
||||||
Loading…
Add table
Reference in a new issue