Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过Python读取Outlook事件_Python_Python 2.7_Outlook 2010_Win32com - Fatal编程技术网

通过Python读取Outlook事件

通过Python读取Outlook事件,python,python-2.7,outlook-2010,win32com,Python,Python 2.7,Outlook 2010,Win32com,Outlook需要一些东西,比如显示多月视图 所以我决定尝试一下,通过python提取事件数据(然后找到一种很好地显示它的方法)。谷歌给了我一些搜索结果,但是stackoverflow以前在使用win32com和outlook方面非常有用 我的目标如下 阅读共享日历 阅读事件信息,如开始、结束、主题、创建者等 我还没走多远,但这就是我的灵感来源 在这里,我需要帮助循环浏览事件并阅读它们。非常感谢您的帮助 在这里,我需要帮助循环浏览事件并阅读它们 基本上,您所要做的就是遵循Microsoft提

Outlook需要一些东西,比如显示多月视图

所以我决定尝试一下,通过python提取事件数据(然后找到一种很好地显示它的方法)。谷歌给了我一些搜索结果,但是stackoverflow以前在使用win32com和outlook方面非常有用

我的目标如下

  • 阅读共享日历
  • 阅读事件信息,如开始、结束、主题、创建者等
我还没走多远,但这就是我的灵感来源

在这里,我需要帮助循环浏览事件并阅读它们。非常感谢您的帮助

在这里,我需要帮助循环浏览事件并阅读它们

基本上,您所要做的就是遵循Microsoft提供的COM API文档。例如,
Restrict()
方法返回在For Outlook 2010中记录的
AppointItem
对象。因此,从文件夹开始,您可以按如下方式获取并列出约会:

# Get the AppointmentItem objects
# http://msdn.microsoft.com/en-us/library/office/aa210899(v=office.11).aspx
appointments = someFolder.Items

# Restrict to items in the next 30 days (using Python 3.3 - might be slightly different for 2.7)
begin = datetime.date.today()
end = begin + datetime.timedelta(days = 30);
restriction = "[Start] >= '" + begin.strftime("%m/%d/%Y") + "' AND [End] <= '" +end.strftime("%m/%d/%Y") + "'"
restrictedItems = appointments.Restrict(restriction)

# Iterate through restricted AppointmentItems and print them
for appointmentItem in restrictedItems:
    print("{0} Start: {1}, End: {2}, Organizer: {3}".format(
          appointmentItem.Subject, appointmentItem.Start, 
          appointmentItem.End, appointmentItem.Organizer))
要将所有可用文件夹显示为树,可以使用

def folderTree(folders, indent = 0):
    prefix = ' ' * (indent*2)
    i = 0
    for folder in folders:
        print("{0}{1}. {2} ({3})".format(prefix, i, folder.Name, folder.DefaultItemType))
        folderTree(folder.Folders, indent + 1)
        i = i + 1

...
folderTree(namespace.Folders)
def findFolder(folders, searchPath, level = 0):
    for folder in folders:
        if folder.Name == searchPath[level]:
            if level < len(searchPath)-1:
                # Search sub folder
                folder = findFolder(folder.folders, searchPath, level+1)
            return folder
    return None

...
sharedCalendar = findFolder(namespace.Folders, ["Internet Calendars", "Norfeld@so.com"])
按文件夹路径查找文件夹(例如查找日历文件夹)Norfeld@so.com在“Internet日历”文件夹下),您可以使用

def folderTree(folders, indent = 0):
    prefix = ' ' * (indent*2)
    i = 0
    for folder in folders:
        print("{0}{1}. {2} ({3})".format(prefix, i, folder.Name, folder.DefaultItemType))
        folderTree(folder.Folders, indent + 1)
        i = i + 1

...
folderTree(namespace.Folders)
def findFolder(folders, searchPath, level = 0):
    for folder in folders:
        if folder.Name == searchPath[level]:
            if level < len(searchPath)-1:
                # Search sub folder
                folder = findFolder(folder.folders, searchPath, level+1)
            return folder
    return None

...
sharedCalendar = findFolder(namespace.Folders, ["Internet Calendars", "Norfeld@so.com"])
def findFolder(文件夹,搜索路径,级别=0): 对于文件夹中的文件夹: 如果folder.Name==searchPath[level]: 如果级别 另见:

  • (作为我的“Python示例”项目的一部分)

谢谢您的回答-所以我的限制字符串命令是错误的。我发现很难理解MS API。如何选择默认日历以外的其他日历。我认为循环所有日历的名称会很好。我同意COM API不容易阅读-但基本上,模型很容易:有些对象具有方法和属性(以及事件)。方法可以被调用,并且可能返回一个结果,就像对另一个对象的引用一样。属性可以读取(如果不是只读的,则写入),读取可能会再次导致引用另一个对象。一些方法/属性返回可以迭代的COM集合,该集合无缝集成到Python中,以便您可以使用
来。。。在…
。并不是我没有尝试。但就是不能让你的folderTree工作——我需要它来抓取感兴趣的日历。我没有在python中使用类。
用于ns中的文件夹。文件夹:打印文件夹。Name
提供“Internet日历”和“SharePoint列表”my@mail.com假设我想在“Internet日历”中获取日历-如何将收件人名称定义为获取“Internet日历”中日历的字符串Folder您是指
ns.GetDefaultFolder(9)
而不是
名称空间。
?如果我尝试你的代码,我会得到一个名称错误。