Skip to content

Instantly share code, notes, and snippets.

@dyus
Created December 11, 2015 12:27
Show Gist options
  • Save dyus/2461db73eef3219b2298 to your computer and use it in GitHub Desktop.
Save dyus/2461db73eef3219b2298 to your computer and use it in GitHub Desktop.
def get_user_availability(mail, start, end, format=u"Default", time_zone='Europe/Moscow'):
"""
https://msdn.microsoft.com/en-us/library/aa564001(v=exchg.140).aspx
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Body>
<GetUserAvailabilityRequest xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<t:TimeZone xmlns="http://schemas.microsoft.com/exchange/services/2006/types">
<Bias>480</Bias>
<StandardTime>
<Bias>0</Bias>
<Time>02:00:00</Time>
<DayOrder>5</DayOrder>
<Month>10</Month>
<DayOfWeek>Sunday</DayOfWeek>
</StandardTime>
<DaylightTime>
<Bias>-60</Bias>
<Time>02:00:00</Time>
<DayOrder>1</DayOrder>
<Month>4</Month>
<DayOfWeek>Sunday</DayOfWeek>
</DaylightTime>
</t:TimeZone>
<MailboxDataArray>
<t:MailboxData>
<t:Email>
<t:Address>[email protected]</t:Address>
</t:Email>
<t:AttendeeType>Required</t:AttendeeType>
<t:ExcludeConflicts>false</t:ExcludeConflicts>
</t:MailboxData>
<t:MailboxData>
<t:Email>
<t:Address>[email protected]</t:Address>
</t:Email>
<t:AttendeeType>Required</t:AttendeeType>
<t:ExcludeConflicts>false</t:ExcludeConflicts>
</t:MailboxData>
</MailboxDataArray>
<t:FreeBusyViewOptions>
<t:TimeWindow>
<t:StartTime>2006-10-16T00:00:00</t:StartTime>
<t:EndTime>2006-10-16T23:59:59</t:EndTime>
</t:TimeWindow>
<t:MergedFreeBusyIntervalInMinutes>60</t:MergedFreeBusyIntervalInMinutes>
<t:RequestedView>DetailedMerged</t:RequestedView>
</t:FreeBusyViewOptions>
</GetUserAvailabilityRequest>
</soap:Body>
</soap:Envelope>
"""
tz = pytz.timezone('Europe/Moscow')
bias = str(tz.utcoffset(dt.datetime.now()).seconds/60)
start_converted = convert_datetime_to_utc(start)
end_converted = convert_datetime_to_utc(end)
root = M.GetUserAvailabilityRequest(
T.TimeZone(
T.Bias(bias),
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(mail)
),
T.AttendeeType('Required'),
T.ExcludeConflicts('false'),
)
),
T.FreeBusyViewOptions(
T.TimeWindow(
T.StartTime(str(start.strftime(EXCHANGE_DATETIME_FORMAT))),
T.EndTime(str(end.strftime(EXCHANGE_DATETIME_FORMAT))),
),
T.MergedFreeBusyIntervalInMinutes('5'),
T.RequestedView('FreeBusy')
)
)
return root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment