#!/usr/bin/python import sys # --------------------------------------------------------------------------------------------- # -- def write_results(results) : num = 0 for r in results : num = num + 1 sys.stdout.write(" %3s Name : " % (str(num))) sys.stdout.write(r[0] + ", " + r[1]) sys.stdout.write("\n Department : " + r[5]) sys.stdout.write("\n Netware acc : " + str(r[6])) sys.stdout.write("\n Email addr : " + str(r[36])) sys.stdout.write("\n Cosmos uname : " + str(r[37])) sys.stdout.write("\n\n") # --------------------------------------------------------------------------------------------- # -- __MAIN__ : print " " print " Welcome to URSPY." print " " print " Importing UnixODBC stuff..." import mx.ODBC.unixODBC db = mx.ODBC.unixODBC.DriverConnect('DSN=vardywardy;UID=<ursusername>;PWD=<urspassword>') c = db.cursor() print " ...imported." while 1: sys.stdout.write("\n Choose:") sys.stdout.write("\n ") sys.stdout.write("\n 1. Enter username, get other stuff") sys.stdout.write("\n 2. Enter lastname (or first part), get stuff") sys.stdout.write("\n 0. Quit") sys.stdout.write("\n ") sys.stdout.write("\n Choice: ") r = sys.stdin.readline() r = r[:-1] if r == '0': print " " print " ...quitting..." print " " break elif r == '1': sys.stdout.write("\n Enter username: ") name = sys.stdin.readline() name = name[:-1] sql = "SELECT * FROM UserDetails_simon WHERE NetwareAccountName = '" + name + "'" print "\n ...executing SQL query...\n" c.execute(sql) results = c.fetchall() sys.stdout.write(" Results of SQL query : \n\n") write_results(results) elif r == '2': sys.stdout.write("\n Enter lastname: ") name = sys.stdin.readline() name = name[:-1] sql = "SELECT * FROM UserDetails_simon WHERE LastName LIKE '" + name + "%'" print "\n ...executing SQL query...\n" c.execute(sql) results = c.fetchall() sys.stdout.write(" Results of SQL query : \n\n") write_results(results) else : sys.stdout.write(" ???") sys.stdout.write("\n ") c.close() # --------------------------------------------------------------------------------------------- # -- Tea Time. # ---------------------------------------------------------------------------------------------