python - 通过 Python 阅读 Outlook 共享日历
问题描述
使用 Python,您如何阅读 Outlook 的共享日历事件,并希望还使用时间过滤器?
解决方案
这是一个相关的帖子,但要完全回答这个问题:
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)
推荐阅读
- javascript - 定位兄弟元素的子元素
- wso2 - 如何在 wso2 DSS 中查询 HBASE
- vb.net - vb自动将文本框的内容导出到PC上的txt文件中,每个文件具有不同的名称
- c# - .Net Core 2.1 中的动态代码编译
- powershell - Robocopy as another user
- react-native - 在导航 goBack 上发送道具
- google-cloud-platform - 需要 GCP 计费支持 - 服务已停止但仍需收费
- vba - 根据检测到的 Word 版本在 Word 功能区上显示自定义选项卡?
- android - 如何通过 Kotlin 中的数据绑定设置 Android 复合视图的可见性?
- javascript - javascript停止工作但在不同的服务器上工作