CoCalc Public Filesmake_staff_csv.sagewsOpen in with one click!
Author: Tim Clemans SMC
Views : 38
headers = 'colour email_address full_name id job_title mugshot_url_template parent phone_numbers statistic_1 statistic_2 summary'.split() import requests data = requests.get('$limit=14000').json() print headers import csv import sys manager_to_id = {} for i, row in enumerate(data): manager_to_id[row['employee']] = i f = open('example.csv', 'wt') secret_folks = [] try: writer = csv.writer(f) writer.writerow( headers ) for i, row in enumerate(data): if not row.get('employee_manager_name') and 'mayor' != row['job_title'].lower(): # some people don't have a listed manager so making their manager the Mayor #print i, row #continue manager_id = manager_to_id.get('Murray, Edward') else: manager_id = manager_to_id.get(row.get('employee_manager_name', ''), '') if not manager_id and 'mayor' != row['job_title'].lower(): secret_folks.append(row.get('employee_manager_name', '')) manager_id = manager_to_id.get('Murray, Edward') #print i, row rowlist = ['#000000','',row['employee'],i,row['job_title']+', '+row['department'],'',manager_id,'','','',''] writer.writerow( rowlist ) finally: f.close() print set(secret_folks) #print open('example.csv', 'rt').read()
['colour', 'email_address', 'full_name', 'id', 'job_title', 'mugshot_url_template', 'parent', 'phone_numbers', 'statistic_1', 'statistic_2', 'summary'] set([u'Jones, Diane', u'Beckett, Jani', u'Licata, Nicholas', u'Noell, Sharon', u'Gau, Dennis', u'Chagzoetsang, Doma', u'Trolio, Thomas', u'Skinner, Jeffrey', u'Milton, Joshua', u'Davies, Shae', u'Combs, Bradley', u'Franklin, Nicole', u'Lawrence-McClain, Angelica', u'Gilbertson, David', u'User Manager Name', u'Boler, Jean', u'Wilkens, Robert', u'Video, Frank'])