0

I am trying to get all appointments from client outlook with python and win32com. client, I just want to get all appointments from 2019 so that I could restrict the appointment Items, but when I restrict them I don't get the recurring appointments.

I already tried to enable recurring items with appointments.IncludeRecurrences = "True", but that didn't help.

import win32com.client
import time
import datetime
import os


f=open("mem.txt", "w")
counter=0
outlook= win32com.client.Dispatch("Outlook.Application")
namespace=outlook.GetNamespace("MAPI")
recipient = namespace.createRecipient("Some Calender")
resolved = recipient.Resolve()
sharedCalendar = namespace.GetSharedDefaultFolder(recipient, 9)
appointments = sharedCalendar.Items

# Restrict items
begin = datetime.date(2019, 1, 1)
end = datetime.date(2019, 12, 30)
restriction = "[Start] >= '" + begin.strftime("%m/%d/%Y") + "' AND [End] <= '" +end.strftime("%m/%d/%Y") + "'"
restrictedItems = appointments.Restrict(restriction)
appointments.IncludeRecurrences = "True"

# Iterate through restricted AppointmentItems
for appointmentItem in restrictedItems:
    month= appointmentItem.Start
    month=str(month)[5:-18] #just trim the month out of the date
    if month=='08': #need appointments from specific
        #mystuff
        #the code works but I want the recurring appointments too
print(counter)
f.close()
Prashant Mishra
  • 619
  • 9
  • 25
Vcdf Ggg
  • 1
  • 1

2 Answers2

0

Did you try setting IncludeRecurrences to True before Restricting your items ?

Basically switching those two lines :

restrictedItems = appointments.Restrict(restriction)
appointments.IncludeRecurrences = "True"
vincenthavinh
  • 442
  • 4
  • 12
  • Can you read C# ? I found an answer to the same question but in C#. It says to add in your loop an if-then statement evaluating the IsRecurring property : https://stackoverflow.com/a/8044268/11269264 – vincenthavinh Jun 24 '19 at 09:28
0

Firstly, to retrieve all Outlook appointment items from the folder that meets the predefined condition, you need to sort the items in ascending order and set the IncludeRecurrences to true. You will not catch recurrent appointments if you don’t do this before using the Restrict method!

    folderItems = folder.Items;
    folderItems.IncludeRecurrences = true;
    folderItems.Sort("[Start]");
    resultItems = folderItems.Restrict(restrictCriteria);

You may find the following articles helpful:

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45