hackertours-schedule/voc/webcal.py
2025-11-18 19:05:41 +01:00

57 lines
No EOL
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import re
import ics
import requests
from voc import GenericConference
from voc.event import Event, EventSourceInterface
from voc.schedule import Schedule, ScheduleException
from voc.tools import format_duration, gen_person_uuid
class WebcalConference(GenericConference, EventSourceInterface):
def __init__(self, **args):
GenericConference.__init__(self, **args)
def schedule(self, template: Schedule):
if not self.schedule_url or self.schedule_url == 'TBD':
raise ScheduleException(' has no schedule url yet ignoring')
url = re.sub(r'^webcal', 'http', self.schedule_url)
data = requests.get(url, timeout=10).text
cal = ics.Calendar(data)
schedule = template.copy(self['name']) or Schedule(conference=self)
for e in cal.events:
event = Event(convert_to_dict(e, self), origin=self)
schedule.add_event(event)
return schedule
def convert_to_dict(e: ics.Event, context: WebcalConference) -> dict:
title, subtitle, event_type = re.match(r"^(.+?)(?:( ?[:] .+?))?(?: \((.+?)\))?$", e.name).groups()
track, = list(e.categories) or [None]
return {
"guid": e.uid,
"title": title,
"subtitle": subtitle,
"abstract": e.description,
"description": '', # empty description for pretalx importer (temporary workaround)
"date": e.begin.isoformat(),
"start": e.begin.format("HH:mm"),
"duration": format_duration(e.duration),
"room": e.location or context['name'],
"persons": [{
"name": p.common_name,
"guid": gen_person_uuid(p.email.replace('mailto:', '')),
# TODO: add p.role?
} for p in e.attendees],
"track": track,
"type": event_type or 'Other',
"url": e.url or None,
}
if __name__ == '__main__':
WebcalConference()