outlook events for orgmode
If like me you spend all your working life in MS products and yet you still want to or do rely on orgmode to give you some semblance of sanity, then this might help. Its not a bidirectional synchronisation and i only wanted the appointments for today to show. It queries Outlook for any confirmed appointments in the calendar and then outputs a single orgmode file in my main org folder which is automatically added to the agenda. The following code originally taken from https://sukhbinder.wordpress.com/2020/04/08/get-outlook-entries-with-python-3/ then gutted and adapted for my needs queries MS Outlook for the events in the calendar. I've restricted it for one day but changing the variable num_days can output more if you wanted.
# taken from https://sukhbinder.wordpress.com/2020/04/08/get-outlook-entries-with-python-3/ # modified 2020.08.07 import win32com.client import datetime as dt f = open('C:/Users/lee.halls/Documents/orgfiles/today.org', 'w') def getEndtime(start_time,org_duration): org_duration = org_duration / 60 the_time = dt.datetime.strptime(start_time, '%H:%M') new_time = the_time + dt.timedelta(hours=org_duration) return new_time.strftime('%H:%M') Outlook = win32com.client.Dispatch("Outlook.Application") ns = Outlook.GetNamespace("MAPI") appointments = ns.GetDefaultFolder(9).Items appointments.Sort("[Start]") appointments.IncludeRecurrences = "True" # define date range num_days = 1 today = dt.datetime.today() begin = today.date().strftime("%d/%m/%Y") tomorrow = dt.timedelta(num_days) + today end = tomorrow.date().strftime("%d/%m/%Y") # restrict appointments in outlook to today appointments = appointments.Restrict( "[Start] >= '" + begin + "' AND [END] <= '" + end + "'") # loop through appointments for a in appointments: #print(a.Subject, a.Start, a.Duration) startTime = (a.Start).strftime("%H:%M") endTime = getEndtime(startTime, a.Duration) # print ('%s%s%s%s%s%s%s' % ('* ', startTime ,'-', endTime, ' ', a.Subject, '\n')) # print ('%s%s%s' % ('<', a.Start.strftime('%Y-%m-%d'), '>')) f.write ('%s%s%s%s%s%s%s' % ('* ', startTime ,'-', endTime, ' ', a.Subject, '\n')) f.write ('%s%s%s%s' % ('<', a.Start.strftime('%Y-%m-%d'), '>', '\n' )) f.close()
I've set this to run via windows task scheduler every time i unlock the PC.