Outlook FreeBusy method giving incorrect output

寵の児 提交于 2020-01-05 21:23:51

问题


With reference to the question, I have written solution but somehow this doesn't seems to be working properly. I checked calander and meeting room is available but as per below code, meeting room is showing full and also I have seen reverse case where meeting room is booked while below code shows the availability.

import win32com.client
import pywintypes
import datetime

class MeetingRoom:
    def __init__(self,inputDate, duration, locationMail):
        self.inputDate = inputDate
        self.oOutlook = win32com.client.Dispatch("Outlook.Application")
        self.bookings = self.oOutlook.CreateItem(1)
        self.bookings.Start = inputDate
        self.bookings.Duration = duration
        self.bookings.Subject = 'Follow Up Meeting'
        self.bookings.Location = '<Name of meeting room>'
        self.bookings.MeetingStatus = 1
        self.roomRecipient = self.bookings.Recipients.Add(locationMail)

    def checkRoomAvailability(self):
        bookingDateTime = datetime.datetime.strptime(self.inputDate,'%Y-%m-%d %H:%M:%S')
        self.roomRecipient.resolve
        myDate = bookingDateTime.date()
        # print(myDate)
        # myDate = datetime.date(2018, 5, 23)
        pywintypeDate = pywintypes.Time(myDate)
        availabilityInfo = self.roomRecipient.FreeBusy(pywintypeDate, self.bookings.Duration, True)
        timeAvailability = []
        newTime = pywintypeDate
        # print(newTime)
        currentTime = datetime.datetime.now()
        for isAvailable in availabilityInfo:
            # print(newTime, " :: ", isAvailable)
            if isAvailable == "0" and newTime >= currentTime:
                timeAvailability.append(newTime)
            newTime = newTime + datetime.timedelta(minutes=self.bookings.Duration)

        print(availabilityInfo)
        # for value in timeAvailability:
        #     print(value)
        try:
            index = timeAvailability.index(bookingDateTime)
            print("room available")
            # self.bookings.Save()
            # self.bookings.Send()

        except ValueError:
            for timestamp in timeAvailability:
                if bookingDateTime < timestamp:
                    break
            print("I dont see availability of meeting rooms at ", bookingDateTime, " but next available time is ", timestamp)

        # def bookMeetingRoom():

if __name__ ==  '__main__':
    meetingRoomObj = MeetingRoom("2018-05-23 11:30:00",60,"<mail_id_of_meeting_room")
    meetingRoomObj.checkRoomAvailability()

来源:https://stackoverflow.com/questions/50441215/outlook-freebusy-method-giving-incorrect-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!