library/calendar_sync.py aktualisiert
This commit is contained in:
@ -47,14 +47,20 @@ def sync_ics_to_caldav(module):
|
||||
module.params['verify_ssl']
|
||||
)
|
||||
|
||||
existing_events = {
|
||||
str(event.icalendar_component.uid): event
|
||||
for event in target_cal.events()
|
||||
}
|
||||
# Bestehende Events aus dem Zielkalender einlesen und UIDs extrahieren
|
||||
existing_events = {}
|
||||
for event in target_cal.events():
|
||||
try:
|
||||
vobj = vobject.readOne(event.data)
|
||||
uid = str(vobj.vevent.uid)
|
||||
existing_events[uid] = event
|
||||
except Exception as e:
|
||||
raise Exception(f"Fehler beim Parsen eines bestehenden Events: {str(e)}")
|
||||
|
||||
changed = False
|
||||
results = {'added': [], 'updated': [], 'removed': []}
|
||||
|
||||
# Neue ICS-Events einfügen oder updaten
|
||||
for vevent in ics_events:
|
||||
uid = str(vevent.uid)
|
||||
ical_data = vevent.serialize()
|
||||
@ -69,6 +75,7 @@ def sync_ics_to_caldav(module):
|
||||
results['updated'].append(uid)
|
||||
changed = True
|
||||
|
||||
# Nicht mehr vorhandene Events löschen, wenn gewünscht
|
||||
if module.params['purge']:
|
||||
current_uids = {str(e.uid) for e in ics_events}
|
||||
for uid in set(existing_events.keys()) - current_uids:
|
||||
|
||||
Reference in New Issue
Block a user