본문 바로가기

개발/Python

[Python] Outlook 일정 데이터 가져오기

반응형
import datetime as dt
import win32com.client

def get_calendar(begin,end):
    outlook = win32com.client.Dispatch('Outlook.Application').GetNamespace('MAPI')
    calendar = outlook.getDefaultFolder(9).Items
    calendar.IncludeRecurrences = True
    calendar.Sort('[Start]')
    restriction = "[Start] >= '" + begin.strftime('%m/%d/%Y') + "' AND [END] <= '" + end.strftime('%m/%d/%Y') + "'"
    calendar = calendar.Restrict(restriction)
    return calendar

begin = dt.datetime(2021,6,1)
end = dt.datetime(2021,6,30)

cal = get_calendar(begin, end)

for appointmentItem in cal:
    cal_subject = appointmentItem.subject     # 제목
    cal_start = appointmentItem.start         # 시작 시간
    cal_end = appointmentItem.end             # 종료 시간
    cal_body = appointmentItem.body           # 내용
    cal_location = appointmentItem.location   # 위치
    cal_allday = appointmentItem.AllDayEvent  # 하루 종일
    cal_category = appointmentItem.Categories # 범주
    
    print('{}\n{}\n{}\n{}\n{}\n{}'.format(cal_subject, cal_start, cal_end, cal_location, cal_allday, cal_category))

6번째줄의 outlook.getDefaultFolder(9) 에 들어가는 변수 값의 정보는 아래 MS 문서를 참고한다.

 

OlDefaultFolders enumeration (Outlook)

 

docs.microsoft.com

반응형

자바스크립트를 허용해주세요.
[ 자바스크립트 활성화 방법 ]
from Mohon Aktifkan Javascript!