#!/usr/bin/python # Converts from myUB format to WebAssign-acceptable format # place in directory with infile.csv (obtained from myUB) # and type something like: # ./webassignconvert.py < infile.csv > outfile.csv # The file outfile.csv should contain a csv file you can upload to Webassign. # Version 1.0 by Jason Fox Manning, August 27, 2007. import sys, getopt, csv def usage(): print "Usage: webassignconvert.py -i infile.csv -o outfile.csv \nor use as a filter: webassignconvert.py < infile.csv > outfile.csv" def reorganize(infile,outfile): reader = csv.reader(infile) writer = csv.writer(outfile) notonfirstrow = False #Hack to skip first row writer.writerow(['username','fullname','password','email','ssn']) for row in reader: if len(row)>0: student_id = row[0] name = row[1] last_name = name[:name.find(',')] first_name = name[name.find(',')+1:] status = 'c' comment = '' section = row[16] recitation = '' email = row[2] user_id = email[:email.find('@')] password = '' #this will set password equal to student ID permission = '0' newrow = [user_id,name,student_id,email,student_id] if notonfirstrow: writer.writerow(newrow) notonfirstrow = True def main(): try: opts, args = getopt.getopt(sys.argv[1:], "hi:o:", ["help", "input=", "output="]) except getopt.GetoptError, err: # print help information and exit: print str(err) usage() sys.exit(2) infile = sys.stdin # set infile and outfile to standard streams as default outfile = sys.stdout for o, a in opts: if o in ("-i","--input"): infile = open(a,'r') if o in ("-o", "--output"): outfile = open(a,'w') if o in ("-h", "--help"): usage() sys.exit() reorganize(infile,outfile) infile.close() outfile.close() if __name__ == "__main__": main()