包括定期约会

时间:2019-06-24 07:46:37

标签: python outlook win32com

我正在尝试使用python和win32com从客户端前景中获取所有约会。客户,我只想获取2019年以来的所有约会,以便可以限制约会项目,但是当我限制它们时,我不会获得定期约会。

我已经尝试启用具有约会功能的重复项目。IncludeRecurrences=“ True”,但这没有帮助。

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()

2 个答案:

答案 0 :(得分:0)

您是否在限制商品之前尝试将IncludeRecurrences设置为True

基本上切换这两行:

restrictedItems = appointments.Restrict(restriction)
appointments.IncludeRecurrences = "True"

答案 1 :(得分:0)

首先,要从符合预定义条件的文件夹中检索所有Outlook约会项目,您需要按升序对项目进行排序并将IncludeRecurrences设置为true。如果您在使用Restrict方法之前不这样做,则不会捕获定期约会!

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

您可能会发现以下文章有帮助: