Created
January 20, 2015 22:54
-
-
Save catermelon/23f99486e8cdd11257d6 to your computer and use it in GitHub Desktop.
PyExchange Stackoverflow answer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyexchange import Exchange2010Service, ExchangeNTLMAuthConnection | |
from datetime import datetime | |
import time | |
from pytz import timezone, utc | |
def getEvents(): | |
URL = u'https://blah.blah/EWS/exchange.asmx' | |
USERNAME = u'DOMAIN\\user' | |
PASSWORD = u"password" | |
connection = ExchangeNTLMAuthConnection(url=URL, | |
username=USERNAME, | |
password=PASSWORD) | |
service = Exchange2010Service(connection) | |
local_tz = timezone("Europe/Amsterdam") | |
timestamp = datetime.now() | |
print timestamp.strftime('%Y, %m, %d, %H, %M, %S') | |
print time.timezone | |
start = datetime(2015, 1, 19, 0, 0, 0) | |
start = local_tz.localize(start) | |
start = start.astimezone(pytz.utc) | |
end = datetime(2015, 1, 19, 23, 59, 59) | |
end = local_tz.localize(end) | |
end = end.astimezone(utc) | |
eventsList = service.calendar().list_events( | |
start=start, | |
end=end, | |
details=True | |
) | |
for event in eventsList.events: | |
print "{start} {stop} - {subject} - {room}".format( | |
start=event.start.astimezone(local_tz), | |
stop=event.end.astimezone(local_tz), | |
subject=event.subject, | |
room=event.location | |
) | |
getEvents() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment