I'm trying to retrieving free/busy status from outlook calender for particular person using python language.
here is my code for it.
import win32com.client
obj_outlook = win32com.client.Dispatch('Outlook.Application')
obj_Namespace = obj_outlook.GetNamespace("MAPI")
obj_Recipient = obj_Namespace.CreateRecipient("someone@domain.com")
str_Free_Busy_Data = obj_Recipient.FreeBusy("11-11-2013", 11)
print str_Free_Busy_Data
but I'm getting an error:
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
str_Free_Busy_Data = obj_Recipient.FreeBusy("11-11-2013", 11)
File "<COMObject CreateRecipient>", line 4, in FreeBusy
TypeError: an integer is required
So my question is Recipient.FreeBusy() method takes two mandatory arguments, Start Date and duration. Here 11 is the duration, which is an Integer. So why python is not able to identify the integer argument here and returning an TypeError.
Please help me in case I have done anything wrong (I'm still a newbie in python world).
Thanks in advance.
I looked up the method in MSDN.
http://msdn.microsoft.com/en-us/library/office/microsoft.office.interop.outlook.recipient.freebusy(v=office.12).aspx
The syntax for the method takes 3 arguments.
string FreeBusy(
DateTime Start,
int MinPerChar,
Object CompleteFormat
)
The issue is that you're passing a string to the DateTime parameter. Instead you need to import the datetime library in your code and use a date parameter.
So, at the start of your code, try this.
import datetime
#Then declare the my_date variable as datetime.date.
my_date = datetime.date(2013,11,23)
str_Free_Busy_Data = obj_Recipient.FreeBusy(my_date, 11)
The first parameter to FreeBusy
is a Date
object. Pywin won't convert a string into a Date
, but it can convert a pywintypes.Time
object, or an integer representing the number of seconds since the Unix epoch. Hence the error: When the first argument is implicitly converted to a Time
, the constructor complains that it needs an integer.
#start date: 12/31/1969 7:00:00 PM
str_Free_Busy_Data = obj_Recipient.FreeBusy(0, 11)
There are a number of ways to get the Unix timestamp from a date. See Convert python datetime to epoch with strftime.