Outlook名称空间-访问公共但受限的日历

时间:2019-01-18 13:38:30

标签: python outlook win32com

我正在编写一个脚本,该脚本应该显示我们拥有的每个会议室,并显示它们是否有空。我正在使用Python和win32com。我可以通过这种方式轻松访问所有会议:

async existsDatabase(myDatabase) {
    return !(await alasql.promise(`
        create indexeddb database if not exists ${myDatabase};
    `));
}

这样,当我使用自己的名字时,我会返回今天的所有会议:

drop indexeddb database if exists ${myDatabase};

当我将其更改为AnotherPerson时(我可以在前景中看到他们的日历!),即使他们今天有会议,我也只能得到一个空数组。

import win32com.client, datetime
def getCalendarEntries(days=1):
    """
    Returns calender entries for days default is 1
    """

    #MailboxToAccess = "MeetingRoomName@Company"
    MailboxToAccess = "MyName@Company"
    #MailboxToAccess = "AnotherPerson@Company"


    Outlook = win32com.client.Dispatch("Outlook.Application")
    ns = Outlook.GetNamespace("MAPI")

    recip = ns.CreateRecipient(MailboxToAccess)
    calendar = ns.GetSharedDefaultFolder(recip, 9)

    appointments = calendar.Items


    appointments.Sort("[Start]")
    appointments.IncludeRecurrences = "True"
    today = datetime.datetime.today()
    begin = today.date().strftime("%m/%d/%Y")
    tomorrow= datetime.timedelta(days=days)+today
    end = tomorrow.date().strftime("%m/%d/%Y")
    appointments = appointments.Restrict("[Start] >= '" +begin+ "' AND [END] <= '" +end+ "'")
    events={'Start':[],'Subject':[],'Duration':[]}
    for a in appointments:
        adate=(str(a.Start))
        #print a.Start, a.Subject,a.Duration
        events['Start'].append(adate)
        events['Subject'].append(a.Subject)
        events['Duration'].append(a.Duration)
    return events
print (getCalendarEntries())

当我使用MeetingRoomName(实际上是我们将会议室阻止程序发送到的电子邮件地址)时,我得到以下错误。到这个会议室,我们所有人都有查看权限,我们可以看到每个会议,他们花多长时间和他们的名字,但是在Python中,我得到了这样的信息:

{'Start': ['2019-01-18 12:30:00+00:00', '2019-01-18 15:00:00+00:00'], 'Subject': ['Outlook python test object', 'Outlook python test object 2'], 'Duration': [60, 60]}

我知道{'Start': [], 'Subject': [], 'Duration': []} 的方法,但是只显示给定时间段的状态。 (这意味着我必须发送16个请求,才能在8小时内获得单个房间的忙/闲状态)

我在这里做错什么了吗?预先谢谢你!

0 个答案:

没有答案