From e0840cb18e54c37c78a9842d453758b1d6e192d3 Mon Sep 17 00:00:00 2001 From: Alex Dehnert Date: Sun, 18 Nov 2012 18:27:12 -0500 Subject: [PATCH] Remove card-access script The ASA DB now includes similar functionality (given list of usernames, produce stuff to send to CAC). --- card-access | 62 ----------------------------------------------------- 1 file changed, 62 deletions(-) delete mode 100755 card-access diff --git a/card-access b/card-access deleted file mode 100755 index 2362720..0000000 --- a/card-access +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/python - -import sys -import os -import csv -import subprocess -import ldap - -#columns = [ 'timestamp', 'first', 'last', 'email', 'constituency', 'year', 'major', 'cell', 'mitid', 'retreat', 'whynot', 'project', 'othermit', ] -format = "%(first_with_initial)s;%(last_canonical)s;%(mitid)s" - -def dictize_line(header, line,): - line_dict = {} - for key, elem in zip(header, line, ): - line_dict[key]=elem - return line_dict - - - -def get_ldap_data(username, fields): - con = ldap.open('ldap.mit.edu') - con.simple_bind_s("", "") - dn = "dc=mit,dc=edu" - result = con.search_s('dc=mit,dc=edu', ldap.SCOPE_SUBTREE, 'uid=%s'%username, fields) - if len(result) > 1: print "WARNING: More than one result returned for %s" % username - if len(result) < 1: print "WARNING: Only one result returned for %s" % username - ret = {} - for key in result[0][1]: - ret[key] = result[0][1][key][0] - return ret - -def get_data_dict(line_dict): - email = line_dict['email'] - username = email.lower().replace('@mit.edu', '') - ldap = get_ldap_data(username, [ 'cn' , 'sn' , 'givenName' ]) - first = ldap['givenName'].replace(' ', '_').upper() - last = ldap['sn'].replace(' ', '_').upper() - mitid = line_dict['mitid'] - data_dict = { 'first_with_initial': first, 'last_canonical': last, 'mitid': mitid } - return data_dict - -def format_line(data_dict): - return format % data_dict - - -def do_produce_card_info(db = sys.stdin): - reader = csv.reader(db, ) - lines = [] - - header = reader.next() - line_dict = dictize_line(header, header, ) - data_dict = { 'first_with_initial': 'FIRST_M', 'last_canonical': 'LASTNAME', 'mitid': 'MIT ID' } - lines.append(format_line(data_dict)) - - for line in reader: - line_dict = dictize_line(header, line) - print line_dict - lines.append(format_line(get_data_dict(line_dict))) - print '\n'.join(lines) - -if __name__== '__main__': - do_produce_card_info() -- 2.34.1