fix: Handle end time being unset in some cases
This commit is contained in:
parent
0c446bcffb
commit
2441225650
1 changed files with 18 additions and 15 deletions
|
@ -21,21 +21,24 @@ cal = icalendar.Calendar()
|
||||||
cal.add('prodid', '-//Bitlair event calendar//bitlair.nl//')
|
cal.add('prodid', '-//Bitlair event calendar//bitlair.nl//')
|
||||||
cal.add('version', '2.0')
|
cal.add('version', '2.0')
|
||||||
|
|
||||||
for key, value in events['results'].items():
|
for page_path, value in events['results'].items():
|
||||||
# unix timestamps from semwiki are not in UTC but in $localtime
|
# Unix timestamps from semwiki are not in UTC but in $localtime
|
||||||
start_time = datetime.fromtimestamp(int(value['printouts']['Start'][0]['timestamp']) - OFFSET)
|
start_time = None
|
||||||
end_time = datetime.fromtimestamp(int(value['printouts']['End'][0]['timestamp']) - OFFSET)
|
end_time = None
|
||||||
|
if (tt := value['printouts']['Start']) and tt:
|
||||||
|
start_time = datetime.fromtimestamp(int(tt[0]['timestamp']) - OFFSET)
|
||||||
|
if (tt := value['printouts']['End']) and tt:
|
||||||
|
end_time = datetime.fromtimestamp(int(tt[0]['timestamp']) - OFFSET)
|
||||||
|
|
||||||
# remove preceding 'Events/YYYY-MM-DD ' if existant from pagename to result in the actual event name
|
if not start_time:
|
||||||
result = re.search(r"Events\/....-..-.. (.*)", key)
|
continue
|
||||||
if result:
|
if not end_time:
|
||||||
groups = result.groups()
|
end_time = start_time + timedelta(hours=4)
|
||||||
if len (groups) == 1:
|
|
||||||
eventname = groups[0]
|
# Remove preceding 'Events/YYYY-MM-DD ' if existant from pagename to result in the actual event name
|
||||||
else:
|
eventname = page_path
|
||||||
eventname = key
|
if (m := re.search(r"Events\/....-..-.. (.*)", page_path)) and m:
|
||||||
else:
|
eventname = m[1]
|
||||||
eventname = key
|
|
||||||
|
|
||||||
# If an event ends when humans are usually asleep, truncate the time range to midnight.
|
# If an event ends when humans are usually asleep, truncate the time range to midnight.
|
||||||
# This prevents calendar items from cluttering the next day when viewed.
|
# This prevents calendar items from cluttering the next day when viewed.
|
||||||
|
@ -45,7 +48,7 @@ for key, value in events['results'].items():
|
||||||
event = icalendar.Event()
|
event = icalendar.Event()
|
||||||
event.add('summary', eventname)
|
event.add('summary', eventname)
|
||||||
|
|
||||||
event.add('description', f'{key}\n {value["fullurl"]}')
|
event.add('description', f'{page_path}\n {value["fullurl"]}')
|
||||||
event.add('dtstamp', datetime.now())
|
event.add('dtstamp', datetime.now())
|
||||||
event.add('dtstart', start_time)
|
event.add('dtstart', start_time)
|
||||||
event.add('dtend', end_time)
|
event.add('dtend', end_time)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue