通过Python读取Outlook共享日历

问题描述 投票:0回答:1

使用Python,如何读取Outlook的共享日历事件,希望也能用一个 时间滤波器?

python automation outlook win32com outlook-2010
1个回答
0
投票

下面是 是一个相关的帖子,但为了全面回答这个问题。

import win32com.client  # for outlook
import datetime

"""This code reads shared calendars."""

# set variables
days = 3
begin = datetime.date.today()
end = begin + datetime.timedelta(days=days)
events = []  # to write results from calendar loop

# begin importing calendar
Outlook = win32com.client.Dispatch("Outlook.Application")
ns = Outlook.GetNamespace("MAPI")

# turn this into a list to read more calendars
recipient = ns.CreateRecipient("username")  # cmd whoami to find this
resolved = recipient.Resolve()  # checks for username in address book

# olFolderCalendar = 9
# appointments = ns.GetDefaultFolder(9).Items  # for personal calendar
appointments = ns.GetSharedDefaultFolder(recipient, 9).Items

# filtering criteria
# https://docs.microsoft.com/en-us/office/vba/api/outlook.items.includerecurrences
appointments.Sort("[Start]")  # suspect problem
appointments.IncludeRecurrences = "True"
restriction = "[Start] >= '" + begin.strftime("%m/%d/%Y") \
            + "' AND [End] <= '" + end.strftime("%m/%d/%Y") + "'"

# list of appointments
restrictedItems = appointments.Restrict(restriction)

# loop through all calendar events, and add elements to list
count = 0
for app in restrictedItems:
    count += 1  # no len(range(restrictedItems)) allowed

#   display values
    print()
    print("item: " + str(count))
    print("start: \t\t" + str(app.Start))
    print("subject: \t" + app.Subject)
    print("end: \t\t" + str(app.End))
    print("recurring: \t" + str(app.IsRecurring))
    print("status: \t" + str(app.MeetingStatus))

    # collect values
    app_instance = [app.Subject,
                    app.Start,
                    app.End,
                    app.BusyStatus]
    events.append(app_instance)
© www.soinside.com 2019 - 2024. All rights reserved.