How to overwrite Outlook calendar events

Viewed 147

So I have this function that creates events on my outlook calendar based on a Dictionary (Later will be data from a database):

def addevent(events):
import win32com.client
for item in table.keys():
    start = '2012-' + item + ' 18:35'
    subject = 'Event Name' + str(table[item])
    oOutlook = win32com.client.Dispatch("Outlook.Application")
    appointment = oOutlook.CreateItem(1) # 1=outlook appointment item
    appointment.Start = start
    appointment.Subject = subject
    appointment.Duration = 20
    appointment.Location = 'Virtual'
    appointment.ReminderSet = True
    appointment.ReminderMinutesBeforeStart = 1
    appointment.Save()
return

However, the issue is that when I re-run it, it adds the same events at the same time but I want it to overwrite events at the same time/ skip the same events. If that makes sense.

1 Answers

After you save the appointment, retrieve its EntryID property and store it. Next time, if the entry id is available, use Namespace.GetItemFromID to reopen the appointment. Otherwise create a new one like you do now.

Related