mirror of
https://git.bolliret.ch/pcs/pcs-website
synced 2026-01-18 15:41:37 +01:00
Improved multi-day event handling.
This commit is contained in:
parent
d44272d9b4
commit
2c9636563d
2 changed files with 54 additions and 22 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from datetime import datetime, date, timedelta
|
from datetime import datetime, date, timedelta, timezone
|
||||||
from typing import Optional, NamedTuple
|
from typing import Optional, NamedTuple
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
|
@ -134,7 +134,23 @@ page.html
|
||||||
|
|
||||||
def get_next_event(self, calendar: Calendar) -> Optional[EventDetails]:
|
def get_next_event(self, calendar: Calendar) -> Optional[EventDetails]:
|
||||||
try:
|
try:
|
||||||
events = split_multiday_events(recurring_ical_events.of(calendar).after(datetime.now()))
|
|
||||||
|
now=datetime.now(timezone.utc) # + timedelta(days=1)
|
||||||
|
|
||||||
|
raw_events = split_multiday_events(recurring_ical_events.of(calendar).after(now))
|
||||||
|
|
||||||
|
now_date = now.date()
|
||||||
|
now_datetime = now
|
||||||
|
events = []
|
||||||
|
for raw_event in raw_events:
|
||||||
|
start = raw_event.get('dtstart').dt
|
||||||
|
if isinstance(start, datetime):
|
||||||
|
my_now = now_datetime
|
||||||
|
else:
|
||||||
|
my_now = now_date
|
||||||
|
if start >= my_now:
|
||||||
|
events.append(raw_event)
|
||||||
|
|
||||||
event = events[0]
|
event = events[0]
|
||||||
start = event.get('dtstart').dt
|
start = event.get('dtstart').dt
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from datetime import datetime, date, timedelta
|
from datetime import datetime, date, timedelta, timezone
|
||||||
import recurring_ical_events
|
import recurring_ical_events
|
||||||
import requests
|
import requests
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
|
@ -63,30 +63,46 @@ def fetch_upcoming_events(ics_url):
|
||||||
response = requests.get(ics_url)
|
response = requests.get(ics_url)
|
||||||
calendar = Calendar.from_ical(response.content)
|
calendar = Calendar.from_ical(response.content)
|
||||||
|
|
||||||
events = split_multiday_events(recurring_ical_events.of(calendar).after(datetime.now()))
|
now=datetime.now(timezone.utc) # + timedelta(days=1)
|
||||||
|
|
||||||
|
raw_events = split_multiday_events(recurring_ical_events.of(calendar).after(now))
|
||||||
|
|
||||||
|
now_date = now.date()
|
||||||
|
now_datetime = now
|
||||||
|
events = []
|
||||||
|
for raw_event in raw_events:
|
||||||
|
start = raw_event.get('dtstart').dt
|
||||||
|
if isinstance(start, datetime):
|
||||||
|
my_now = now_datetime
|
||||||
|
else:
|
||||||
|
my_now = now_date
|
||||||
|
if start >= my_now:
|
||||||
|
events.append(raw_event)
|
||||||
|
|
||||||
for event in events:
|
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
|
start = event.get('dtstart').dt
|
||||||
if isinstance(start, date) and not isinstance(start, datetime):
|
out_summary = event.get('summary')
|
||||||
out_starttime = " "
|
location = event.get('location', 'No location specified')
|
||||||
else:
|
|
||||||
out_starttime = start.strftime('%-H:%M')
|
|
||||||
|
|
||||||
if location != 'No location specified':
|
out_startdate = start.strftime("%a. %-d. %B %Y")
|
||||||
out_location = location
|
|
||||||
else:
|
|
||||||
out_location = " "
|
|
||||||
|
|
||||||
print(f"* <div>{out_summary}</div> ")
|
# Format output based on whether it's an all-day event
|
||||||
print(f" * <div>{out_startdate}</div> ")
|
if isinstance(start, date) and not isinstance(start, datetime):
|
||||||
print(f" * <div>{out_starttime}</div> ")
|
out_starttime = " "
|
||||||
print(f" * <div>{out_location}</div> ")
|
else:
|
||||||
|
out_starttime = start.strftime('%-H:%M')
|
||||||
|
|
||||||
|
if location != 'No location specified':
|
||||||
|
out_location = location
|
||||||
|
else:
|
||||||
|
out_location = " "
|
||||||
|
|
||||||
|
print(f"* <div>{out_summary}</div> ")
|
||||||
|
print(f" * <div>{out_startdate}</div> ")
|
||||||
|
print(f" * <div>{out_starttime}</div> ")
|
||||||
|
print(f" * <div>{out_location}</div> ")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue