Skip to content

Instantly share code, notes, and snippets.

@woolfg
Created October 30, 2018 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woolfg/5b715e8ef3311e51b723b15f42186337 to your computer and use it in GitHub Desktop.
Save woolfg/5b715e8ef3311e51b723b15f42186337 to your computer and use it in GitHub Desktop.
Get a ranked list of people that you spend the most time with in outlook meetings
from datetime import timedelta, datetime
from calendar import monthrange
from exchangelib import DELEGATE, Account, Credentials, EWSDateTime, EWSTimeZone, Configuration
import getpass
email = raw_input('Enter your email address: ')
password = getpass.getpass('Enter your password: ')
credentials = Credentials(email, password)
config = Configuration(server='outlook.office365.com', credentials=credentials)
account = Account(primary_smtp_address=email, config=config, autodiscover=False, access_type=DELEGATE)
tz = EWSTimeZone.timezone('Europe/Vienna')
year = datetime.today().year
result_list_length = 30;
people = {};
for month in range(1,datetime.today().month+1):
print("Fetching calendar entries for month %d..." % month)
start = tz.localize(EWSDateTime(year, month, 1))
if month == datetime.today().month:
end = tz.localize(EWSDateTime(year, month, datetime.today().day))
else:
end = tz.localize(EWSDateTime(year, month, monthrange(year, month)[1]))
for i in account.calendar.view(start=start, end=end):
minutes = (i.end-i.start).total_seconds()/60
if 'required_attendees' in i.__dict__ and i.required_attendees is not None:
for attendee in i.required_attendees:
email = attendee.mailbox.email_address
if email not in people:
people[email] = 0
people[email] = people[email] + minutes
people_sorted = [(k, people[k]) for k in sorted(people, key=people.get, reverse=True)]
print("\nSummary of your meetings in %d: " % year)
for (email,count) in people_sorted[:result_list_length]:
print("%d minutes with %s" % (count,email))
@woolfg
Copy link
Author

woolfg commented Nov 5, 2018

btw, pip install exchangelib should do the magic...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment