password = getpass.getpass(prompt="Password for user %s: " % username)
return exchangelib.ServiceAccount(username,password)
-def ex_login(emailaddr,autodiscover=True):
+def ex_login(emailaddr,ad_cache_path=None):
global exchange_credential
+ autodiscover = True
if exchange_credential is None:
exchange_credential = get_ex_cred()
- return exchangelib.Account(emailaddr,
- credentials = exchange_credential,
- autodiscover = autodiscover)
+ if ad_cache_path is not None:
+ try:
+ with open(ad_cache_path,"rb") as f:
+ url,auth_type = pickle.load(f)
+ autodiscover = False
+ except FileNotFoundError:
+ pass
+
+ if autodiscover:
+ ex_ac = exchangelib.Account(emailaddr,
+ credentials = exchange_credential,
+ autodiscover = autodiscover)
+ if ad_cache_path is not None:
+ cache=(ex_ac.protocol.service_endpoint,
+ ex_ac.protocol.auth_type)
+ with open(ad_cache_path,"wb") as f:
+ pickle.dump(cache,f)
+ else:
+ ex_conf = exchangelib.Configuration(service_endpoint=url,
+ credentials=exchange_credential,
+ auth_type=auth_type)
+ ex_ac = exchangelib.Account(emailaddr,
+ config=ex_conf,
+ autodiscover=False,
+ access_type=exchangelib.DELEGATE)
+
+ return ex_ac
def get_ex_events(calendar):
ans={}
except FileNotFoundError:
cache = None
- ex_account = ex_login("mv3@sanger.ac.uk")
+ ex_account = ex_login("mv3@sanger.ac.uk",".gooswapper_exch_conf.dat")
current = get_ex_events(ex_account.calendar)
gcal_account = gcal_login()