Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions pyexchange/exchange2010/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

class Exchange2010Service(ExchangeServiceSOAP):

def availability(self, email, start, end):
return Exchange2010AvailabilityService(service=self, email=email, start=start, end=end)

def calendar(self, id="calendar"):
return Exchange2010CalendarService(service=self, calendar_id=id)

Expand Down Expand Up @@ -914,3 +917,27 @@ def _parse_parent_id_and_change_key_from_response(self, response):
return id_element.get(u"Id", None), id_element.get(u"ChangeKey", None)
else:
return None, None

class Exchange2010AvailabilityService(object):
def __init__(self, service, email, start, end):
self.service = service
body = soap_request.get_user_availability(email, start=start, end=end)
response_xml = self.service.send(body)
self.service._check_for_errors(response_xml)
self._parse_all_options(response_xml)

def _parse_all_options(self, response):
property_map = {
u'starttime': {u'xpath': u't:StartTime'},
u'endtime': {u'xpath': u't:EndTime'},
}
self.list_slots = []
calendar_events = response.xpath(u'//m:GetUserAvailabilityResponse/m:FreeBusyResponseArray/m:FreeBusyResponse/m:FreeBusyView/t:CalendarEventArray/t:CalendarEvent',
namespaces=soap_request.NAMESPACES)
for event in calendar_events:
self.list_slots.append(self.service._xpath_to_dict(element=event,
property_map=property_map,
namespace_map=soap_request.NAMESPACES)
)
return self.list_slots

84 changes: 84 additions & 0 deletions pyexchange/exchange2010/soap_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,3 +625,87 @@ def update_item(event, updated_attributes, calendar_item_update_operation_type):
)

return root


def get_user_availability(user_email, calendar_id=u'calendar', start=None, end=None,):
"""
<m:GetUserAvailabilityRequest>
<m:MailboxDataArray>
<t:MailboxData>
<t:Email>
<t:Address>mack@contoso.com</t:Address>
</t:Email>
<t:AttendeeType>Organizer</t:AttendeeType>
<t:ExcludeConflicts>false</t:ExcludeConflicts>
</t:MailboxData>
<t:MailboxData>
<t:Email>
<t:Address>sadie@contoso.com</t:Address>
</t:Email>
<t:AttendeeType>Required</t:AttendeeType>
<t:ExcludeConflicts>false</t:ExcludeConflicts>
</t:MailboxData>
</m:MailboxDataArray>
<t:FreeBusyViewOptions>
<t:TimeWindow>
<t:StartTime>2014-02-13T00:00:00</t:StartTime>
<t:EndTime>2014-02-14T00:00:00</t:EndTime>
</t:TimeWindow>
<t:MergedFreeBusyIntervalInMinutes>30</t:MergedFreeBusyIntervalInMinutes>
<t:RequestedView>FreeBusy</t:RequestedView>
</t:FreeBusyViewOptions>
<t:SuggestionsViewOptions>
<t:GoodThreshold>49</t:GoodThreshold>
<t:MaximumResultsByDay>2</t:MaximumResultsByDay>
<t:MaximumNonWorkHourResultsByDay>0</t:MaximumNonWorkHourResultsByDay>
<t:MeetingDurationInMinutes>60</t:MeetingDurationInMinutes>
<t:MinimumSuggestionQuality>Good</t:MinimumSuggestionQuality>
<t:DetailedSuggestionsWindow>
<t:StartTime>2014-02-13T00:00:00</t:StartTime>
<t:EndTime>2014-02-14T00:00:00</t:EndTime>
</t:DetailedSuggestionsWindow>
</t:SuggestionsViewOptions>
</m:GetUserAvailabilityRequest>
"""
start = start.strftime(EXCHANGE_DATETIME_FORMAT)
end = end.strftime(EXCHANGE_DATETIME_FORMAT)

root = M.GetUserAvailabilityRequest(
T.TimeZone(
T.Bias('480'),
T.StandardTime(
T.Bias('0'),
T.Time('02:00:00'),
T.DayOrder('5'),
T.Month('10'),
T.DayOfWeek('Sunday')
),
T.DaylightTime(
T.Bias('-60'),
T.Time('02:00:00'),
T.DayOrder('1'),
T.Month('4'),
T.DayOfWeek('Sunday')
)
),
M.MailboxDataArray(
T.MailboxData(
T.Email(
T.Address(user_email)
),
T.AttendeeType('Required'),
T.ExcludeConflicts('false')
)
),
T.FreeBusyViewOptions(
T.TimeWindow(
T.StartTime(start),
T.EndTime(end),
),
T.MergedFreeBusyIntervalInMinutes('60'),
T.RequestedView('FreeBusy')
)

)

return root