diff --git a/library/calendar_sync.py b/library/calendar_sync.py index 42e1145..561cafd 100644 --- a/library/calendar_sync.py +++ b/library/calendar_sync.py @@ -23,13 +23,11 @@ def connect_caldav(url, user=None, password=None, verify_ssl=True): password=password, ssl_verify_cert=verify_ssl ) - # Kalender-URL in String umwandeln target_path = urlparse(url).path principal = client.principal() - - # Alle Kalender durchsuchen und URL als String vergleichen + for calendar in principal.calendars(): - if target_path in str(calendar.url): # WICHTIG: URL in String konvertieren + if target_path in str(calendar.url): return calendar raise Exception(f"Kalender mit Pfad '{target_path}' nicht gefunden") except Exception as e: @@ -50,7 +48,7 @@ def sync_ics_to_caldav(module): ) existing_events = { - event.icalendar_component.uid.value: event + str(event.icalendar_component.uid): event for event in target_cal.events() } @@ -58,7 +56,7 @@ def sync_ics_to_caldav(module): results = {'added': [], 'updated': [], 'removed': []} for vevent in ics_events: - uid = str(vevent.uid.value) + uid = str(vevent.uid) ical_data = vevent.serialize() if uid not in existing_events: @@ -72,7 +70,8 @@ def sync_ics_to_caldav(module): changed = True if module.params['purge']: - for uid in set(existing_events.keys()) - {str(e.uid.value) for e in ics_events}: + current_uids = {str(e.uid) for e in ics_events} + for uid in set(existing_events.keys()) - current_uids: existing_events[uid].delete() results['removed'].append(uid) changed = True @@ -92,7 +91,7 @@ def run_module(): ) module = AnsibleModule(argument_spec=module_args, supports_check_mode=False) - + try: changed, results = sync_ics_to_caldav(module) module.exit_json(changed=changed, **results) @@ -100,4 +99,4 @@ def run_module(): module.fail_json(msg=str(e)) if __name__ == '__main__': - run_module() \ No newline at end of file + run_module()