参考the question,我已经写了解决方案,但不知怎的,这似乎没有正常工作。我检查过calander并且会议室可用但是根据下面的代码,会议室显示已满,而且我已经看到会议室被预订的反向情况,而下面的代码显示可用性。
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()