library/calendar_sync.py aktualisiert
This commit is contained in:
@ -23,13 +23,11 @@ def connect_caldav(url, user=None, password=None, verify_ssl=True):
|
|||||||
password=password,
|
password=password,
|
||||||
ssl_verify_cert=verify_ssl
|
ssl_verify_cert=verify_ssl
|
||||||
)
|
)
|
||||||
# Kalender-URL in String umwandeln
|
|
||||||
target_path = urlparse(url).path
|
target_path = urlparse(url).path
|
||||||
principal = client.principal()
|
principal = client.principal()
|
||||||
|
|
||||||
# Alle Kalender durchsuchen und URL als String vergleichen
|
|
||||||
for calendar in principal.calendars():
|
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
|
return calendar
|
||||||
raise Exception(f"Kalender mit Pfad '{target_path}' nicht gefunden")
|
raise Exception(f"Kalender mit Pfad '{target_path}' nicht gefunden")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -50,7 +48,7 @@ def sync_ics_to_caldav(module):
|
|||||||
)
|
)
|
||||||
|
|
||||||
existing_events = {
|
existing_events = {
|
||||||
event.icalendar_component.uid.value: event
|
str(event.icalendar_component.uid): event
|
||||||
for event in target_cal.events()
|
for event in target_cal.events()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +56,7 @@ def sync_ics_to_caldav(module):
|
|||||||
results = {'added': [], 'updated': [], 'removed': []}
|
results = {'added': [], 'updated': [], 'removed': []}
|
||||||
|
|
||||||
for vevent in ics_events:
|
for vevent in ics_events:
|
||||||
uid = str(vevent.uid.value)
|
uid = str(vevent.uid)
|
||||||
ical_data = vevent.serialize()
|
ical_data = vevent.serialize()
|
||||||
|
|
||||||
if uid not in existing_events:
|
if uid not in existing_events:
|
||||||
@ -72,7 +70,8 @@ def sync_ics_to_caldav(module):
|
|||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
if module.params['purge']:
|
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()
|
existing_events[uid].delete()
|
||||||
results['removed'].append(uid)
|
results['removed'].append(uid)
|
||||||
changed = True
|
changed = True
|
||||||
|
|||||||
Reference in New Issue
Block a user