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