You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Python pypff库获取Outlook日历(*.pst)事件的起止时间

如何使用Python pypff库获取Outlook日历(*.pst)中事件的开始和结束时间?

关键:识别MAPI属性对应的entry_type

从你提供的record_set数据来看,日历事件的开始/结束时间对应以下entry_type(这些是MAPI标准属性ID):

  • 32772(0x8004):对应PidLidAppointmentStartWhole,事件的本地开始时间(优先使用这个)
  • 32773(0x8005):对应PidLidAppointmentEndWhole,事件的本地结束时间(优先使用这个)
  • 另外32774、32888、32942是重复事件或其他存储形式的开始时间,32775、32943是对应结束时间,单次事件下这些值和主时间一致。

你的Outlook事件显示的2024-01-23 6:30到2024-01-24 9:00,正好匹配entry_type=32772和32773的时间值。

直接提取事件信息的代码示例

不需要复杂的递归遍历所有属性,直接定位日历文件夹,遍历事件消息并提取需要的字段:

import pypff

def get_calendar_events(pst_file_path):
    # 打开PST文件
    pst = pypff.file()
    pst.open(pst_file_path)
    
    # 定位日历文件夹(支持中英文名称)
    root_folder = pst.get_root_folder()
    calendar_folder = None
    for folder in root_folder.sub_folders:
        if folder.name.lower() in ["calendar", "日历"]:
            calendar_folder = folder
            break
    
    if not calendar_folder:
        print("未找到日历文件夹")
        pst.close()
        return
    
    # 遍历所有日历事件
    for event in calendar_folder.sub_messages:
        # 直接获取事件主题
        subject = event.subject or "无主题"
        print(f"事件主题: {subject}")
        
        start_time = None
        end_time = None
        # 遍历record_set提取时间属性
        for record_set in event.record_sets:
            for entry in record_set.entries:
                if entry.entry_type == 32772:
                    start_time = entry.data_as_datetime
                elif entry.entry_type == 32773:
                    end_time = entry.data_as_datetime
        
        # 输出时间信息
        if start_time:
            print(f"开始时间: {start_time.strftime('%Y-%m-%d %H:%M:%S')}")
        if end_time:
            print(f"结束时间: {end_time.strftime('%Y-%m-%d %H:%M:%S')}")
        print("-" * 50)
    
    pst.close()

# 调用示例
get_calendar_events("your_calendar.pst")

补充说明

  1. 日历事件的时间属于MAPI扩展属性,不在message的基础属性列表中,所以必须从record_sets的entries里提取
  2. 事件主题可以直接通过event.subject获取,无需遍历属性
  3. 如果处理重复事件,还可以关注entry_type=32774(重复开始时间)和32775(重复结束时间)

内容的提问来源于stack exchange,提问作者Sergey Petrilin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 13:27:46