Skip to content

Instantly share code, notes, and snippets.

@jdiverp
Last active February 9, 2026 18:37
Show Gist options
  • Select an option

  • Save jdiverp/19a8714a86d8b9627e44a36480845031 to your computer and use it in GitHub Desktop.

Select an option

Save jdiverp/19a8714a86d8b9627e44a36480845031 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import httplib, ssl, socket
import datetime
import urllib2
import json
import sys
PWS_PORT = 443
PWS_HOST = 'wseval.s.uw.edu'
PWS_HOST = 'ws.admin.washington.edu'
KEY_FILE = ''
CERT_FILE = ''
connection = httplib.HTTPSConnection(PWS_HOST, PWS_PORT, KEY_FILE, CERT_FILE)
NAME = ''
METHOD = 'GET'
URL = '/identity/v2/'
ENTITY_URL = URL+'entity/%s.json' % sys.argv[1]
PERSON_FULL_URL = URL+'person/%s/full.xml' % sys.argv[1]
PERSON_FULL_URL = URL+'person/%s/full.json' % sys.argv[1]
URL = ENTITY_URL
URL = PERSON_FULL_URL
connection.request(METHOD, URL)
response = connection.getresponse()
print(datetime.datetime.now().strftime("%Y-%m-%d %H:%M"))
# HTTP status codes, e.g. 200, 404, etc
print('https://'+PWS_HOST+URL)
print("Response status: "+str(response.status))
#print(response.getheaders())
# If we got a 301 redirect lets follow it once
if (response.status == 301):
response.read()
NEW_URL = response.getheader('location')
connection.request(METHOD, NEW_URL)
response = connection.getresponse()
print('https://'+PWS_HOST+NEW_URL)
print("Response status: "+str(response.status))
if (response.status == 404):
response.read()
connection.request(METHOD, ENTITY_URL)
response = connection.getresponse()
print('https://'+PWS_HOST+ENTITY_URL)
print("Response status: "+str(response.status))
if( response.status != 200):
sys.exit()
# must read() response before making additional request()s
body = response.read()
# print(body)
connection.close()
stuff = json.loads(body)
print(json.dumps(stuff, sort_keys=True, indent=2))
if stuff['PersonAffiliations'].has_key('EmployeePersonAffiliation') and stuff['PersonAffiliations']['EmployeePersonAffiliation'].has_key('EmployeeWhitePages'):
employee = stuff['PersonAffiliations']['EmployeePersonAffiliation']
whitepages = employee['EmployeeWhitePages']
#print json.dumps(whitepages['Positions'], sort_keys=True, indent=2)
ewpTitle = ''
ewpDept = ''
if whitepages and whitepages['Positions'] and whitepages['Positions'][0]:
if whitepages['Positions'][0].has_key('EWPTitle') and whitepages['Positions'][0]['EWPTitle'] is not None:
ewpTitle = whitepages['Positions'][0]['EWPTitle']
if whitepages['Positions'][0].has_key('EWPDept') and whitepages['Positions'][0]['EWPDept'] is not None:
ewpDept = whitepages['Positions'][0]['EWPDept']
if whitepages.has_key('Positions') and (whitepages['Positions']) > 0:
print 'EWPTitle: '+ewpTitle
print 'EWPDept: '+ewpDept
print 'HomeDepartment: '+employee['HomeDepartment']
print 'eduPersonAffiliation: '+','.join(stuff['EduPersonAffiliations'])
if stuff['PersonAffiliations'].has_key('EmployeePersonAffiliation'):
print 'EID: '+stuff['PersonAffiliations']['EmployeePersonAffiliation']['EmployeeID']
if stuff['PersonAffiliations'].has_key('StudentPersonAffiliation'):
print 'SID: '+stuff['PersonAffiliations']['StudentPersonAffiliation']['StudentNumber']
if stuff['PersonAffiliations'].has_key('AlumPersonAffiliation'):
print 'AID: '+stuff['PersonAffiliations']['AlumPersonAffiliation']['DevelopmentID']
print 'Registered Name: '+stuff['RegisteredName']
if stuff.has_key('PreferredFirstName') and stuff.has_key('PreferredSurname') and stuff['PreferredFirstName'] is not None and stuff['PreferredSurname'] is not None:
middle = ''
if stuff.has_key('PreferredMiddleName') and stuff['PreferredMiddleName'] is not None:
middle = ' ' + stuff['PreferredMiddleName']
print 'Preferred Name: '+stuff['PreferredFirstName'] + middle + ' ' + stuff['PreferredSurname']
else:
print 'Preferred Name: -not set-'
print 'Display Name: '+stuff['DisplayName']
if stuff.has_key('UWNetID'):
print 'UW NetID: '+stuff['UWNetID']
if stuff.has_key('PriorUWNetIDs'):
print 'Prior UW NetIDs: '+json.dumps(stuff['PriorUWNetIDs'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment