Skip to content

Instantly share code, notes, and snippets.

@moosetraveller
Created November 16, 2021 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moosetraveller/6b391c69b46580df90fbef01b4d6be9b to your computer and use it in GitHub Desktop.
Save moosetraveller/6b391c69b46580df90fbef01b4d6be9b to your computer and use it in GitHub Desktop.
Get Appointments from Outlook
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