Commit e902c393 authored by Alexandre (erdnaxe)'s avatar Alexandre (erdnaxe) 🎇

Make ICS valid

parent e4e25f40
......@@ -14,5 +14,6 @@ selected_groups:
base_url: 'https://agenda.ens-cachan.fr/SOGo/dav/'
calendars_url:
- 'user/Calendar/example.ics'
- 'PUT_YOUR_USERNAME/Calendar/personal.ics'
- 'OTHER_USERNAME_TO_SUSCRIBE/Calendar/example.ics'
......@@ -31,9 +31,15 @@ class OnlineCalendar:
if component.name == 'VTODO':
yield component
def get_timezone(self):
"""Return one timezone"""
for component in self.components.walk():
if component.name == 'VTIMEZONE':
return component
def get_other_components(self):
"""Return all unrecognised components"""
blacklist = ['VEVENT', 'VTODO', 'VCALENDAR', 'DAYLIGHT', 'VTIMEZONE', 'STANDARD']
blacklist = ['VEVENT', 'VTODO', 'VTIMEZONE', 'VCALENDAR', 'DAYLIGHT', 'STANDARD']
for component in self.components.walk():
if component.name not in blacklist:
......
......@@ -9,20 +9,32 @@ from icalendar_tools import OnlineCalendar
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
config = Configuration('config.yml')
# Create master calendar
calendar = Calendar()
calendar.add('prodid', '-//SaphSync//mxm.dk//')
calendar.add('version', '2.0')
# Fetch online calendar and copy components
for url in config.calendars_url:
online_calendar = OnlineCalendar(url, config.login, config.password)
# Copy timezone definitions
tz = online_calendar.get_timezone()
calendar.add_component(tz)
# Copy events
for event in online_calendar.get_events():
# If it is an event in the future and in the correct group
if filter_date(event) and filter_group(event, config.selected_groups):
logging.debug('An event was added : {}'.format(event.get('summary')))
calendar.add_component(event)
# Copy tasks
for todo in online_calendar.get_todos():
logging.debug('A task was added : {}'.format(todo.get('summary')))
calendar.add_component(todo)
# Copy other components
for component in online_calendar.get_other_components():
logging.info('A unrecognised component ({}) was added : {}'.format(component.name, component.to_ical()))
calendar.add_component(component)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment