Created
November 16, 2021 15:35
-
-
Save moosetraveller/6b391c69b46580df90fbef01b4d6be9b to your computer and use it in GitHub Desktop.
Get Appointments from Outlook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd # pip install pandas | |
import win32com.client # pip install pywin32 | |
import datetime as dt | |
def get_calendar(begin, end): | |
""" Source: https://pythoninoffice.com/get-outlook-calendar-meeting-data-using-python """ | |
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 | |
if __name__ == "__main__": | |
start = dt.datetime(2021, 6, 1) | |
end = dt.datetime.today() | |
calendar = get_calendar(start, end) | |
df = pd.DataFrame({ | |
"subject": [appointment.subject for appointment in calendar], | |
"start": [appointment.start for appointment in calendar], | |
"end": [appointment.end for appointment in calendar], | |
}) | |
df["start"] = df["start"].dt.tz_convert(None) | |
df["end"] = df["end"].dt.tz_convert(None) | |
df.to_csv("calendar.csv") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment