diff --git a/config.yml.example b/config.yml.example index a49e16bafa610b5cef80545b30dc1422db3c732b..a61ab3b457ad7efeeae027d215561d7951fb1dcd 100644 --- a/config.yml.example +++ b/config.yml.example @@ -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' diff --git a/icalendar_tools.py b/icalendar_tools.py index 0b8431f196158c158d22bb93cdafe5fde7d0fb10..a6f54e37eb462b7ee425437ffcc604e7c6347215 100644 --- a/icalendar_tools.py +++ b/icalendar_tools.py @@ -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: diff --git a/saphsync.py b/saphsync.py index 17532d88106640134403f29c8a35ba2b46f3d7da..9877a4cb112833ebc86102d0eca24a6ac78b1f14 100644 --- a/saphsync.py +++ b/saphsync.py @@ -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)