Commit e902c393 authored by erdnaxe's avatar erdnaxe 🎇

Make ICS valid

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