Outlook has some things to desire - like showing multiple month view
So I decided to give it a try by pulling out the event data via python (and then figure a way to display it nicely). Google is giving me pore results, but stackoverflow has been very helpful previously in regards to using win32com and outlook.
My goals are the following
- read a shared calendar
- read the events information like start, end, subject, creater etc
I haven't got far, but this is what I got together (with inspiration from this site)
import win32com.client, datetime
from dateutil.relativedelta import relativedelta
Outlook = win32com.client.Dispatch("Outlook.Application")
ns = Outlook.GetNamespace("MAPI")
appointments = namespace.GetDefaultFolder(9).Items
# TODO: Need to figure out howto get the shared calendar instead Default [9]
# (I have placed the shared folder into a separate folder - don't know if it matters)
# I would just like the user to select which calendar to execute on
appointments.Sort("[Start]")
appointments.IncludeRecurrences = "True"
begin = date.today().strftime("%m%d%Y")
end = (date.today() + relativedelta( months = 3 )).strftime("%m%d%Y")
appointments = appointments.Restrict("[Start] >= '" +begin+ "' AND [END] >= '" +end+ "'")
From here I need help with looping through the events and read them. Any help is highly appreciated.
Basically, all you have to do is to follow the COM API documentation from Microsoft. For example, the
Restrict()
method returnsAppointmentItem
objects which are documented at AppointmentItem Object for Outlook 2010. So, starting with a folder, you can get and list the appointments as follows:Note that I had to use a slightly different time format for the restriction expression (
"%m/%d/%Y"
instead of"%m%d%Y"
). The proper solution would be to use Outlook'sFormat
function as documented at http://msdn.microsoft.com/en-us/library/office/ff869597(v=office.14).aspx, section Date. Note also that I was using Python 3.3, so you might have to use different functions to create the dates. In any case, for testing purposes, you can use a hard coded expression like"[Start] >= '02/03/2014' AND [End] <= '03/05/2014'"
To get a shared calendar, the following code should work - This is the usual sequence found in the API documentation, however I was not able to actually get it working, but this could be due to a different backend server (not using an Exchange server):
To show all available folders as a tree, you can use something like
To look up a folder by its path (e.g. to find the calendar folder "Norfeld@so.com" below the "Internet Calendars" folder), you can use something like
See also: