library/calendar_sync.py aktualisiert
This commit is contained in:
@ -41,26 +41,26 @@ def sync_ics_to_caldav(module):
|
|||||||
module.params['source_user'],
|
module.params['source_user'],
|
||||||
module.params['source_password']
|
module.params['source_password']
|
||||||
)
|
)
|
||||||
|
|
||||||
target_cal = connect_caldav(
|
target_cal = connect_caldav(
|
||||||
module.params['target_url'],
|
module.params['target_url'],
|
||||||
module.params['target_user'],
|
module.params['target_user'],
|
||||||
module.params['target_password'],
|
module.params['target_password'],
|
||||||
module.params['verify_ssl']
|
module.params['verify_ssl']
|
||||||
)
|
)
|
||||||
|
|
||||||
existing_events = {
|
existing_events = {
|
||||||
event.icalendar_component.uid.value: event # Korrektur hier
|
event.icalendar_component.uid.value: event
|
||||||
for event in target_cal.events()
|
for event in target_cal.events()
|
||||||
}
|
}
|
||||||
|
|
||||||
changed = False
|
changed = False
|
||||||
results = {'added': [], 'updated': [], 'removed': []}
|
results = {'added': [], 'updated': [], 'removed': []}
|
||||||
|
|
||||||
for vevent in ics_events:
|
for vevent in ics_events:
|
||||||
uid = str(vevent.uid.value) # Korrektur hier
|
uid = str(vevent.uid.value)
|
||||||
ical_data = vevent.serialize()
|
ical_data = vevent.serialize()
|
||||||
|
|
||||||
if uid not in existing_events:
|
if uid not in existing_events:
|
||||||
target_cal.add_event(ical_data)
|
target_cal.add_event(ical_data)
|
||||||
results['added'].append(uid)
|
results['added'].append(uid)
|
||||||
@ -70,13 +70,13 @@ for vevent in ics_events:
|
|||||||
existing_events[uid].save()
|
existing_events[uid].save()
|
||||||
results['updated'].append(uid)
|
results['updated'].append(uid)
|
||||||
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}:
|
for uid in set(existing_events.keys()) - {str(e.uid.value) for e in ics_events}:
|
||||||
existing_events[uid].delete()
|
existing_events[uid].delete()
|
||||||
results['removed'].append(uid)
|
results['removed'].append(uid)
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
return changed, results
|
return changed, results
|
||||||
|
|
||||||
def run_module():
|
def run_module():
|
||||||
|
|||||||
Reference in New Issue
Block a user