#!/usr/bin/env python #Written by Andy Toulouse 9/9/08 #Using argv stuff written by George Wang 9/4/08 #Isolates each students' work on its own page, clips off extra stuff from BeautifulSoup import BeautifulSoup import re import sys if (len(sys.argv) != 3): print "Usage: %s filename outfile" % sys.argv[0] print "neatifyQuiz inserts page breaks between student names" print "filename is the UCWISE grading screen in html." print "outfile is the output filename.\n" sys.exit(1) infile = file(sys.argv[1], 'r') outfile = file(sys.argv[2], 'w') #this is a bit rough around the edges, but does exactly what it's supposed to. #open the file and import it. to be cleaned up. soup = BeautifulSoup(infile) entries = soup.findAll(attrs={'name':re.compile('group\d+')}) students_td = [entry.parent for entry in entries] #students = [(entry.parent.findAll('p',attrs={'class': 'groupNames'})[0].string, str(entry.parent.div)) for entry in entries] students = map(lambda student_td: (str(student_td.findAll('p',attrs={'class': 'groupNames'})[0].string),str(student_td.div)),students_td) print >>outfile,""" Quiz """ for student in students: print >>outfile,"" print >>outfile,"
",student[0],"            /10

" for student in students: #yeah, inefficient, I know, but no biggie since size is small print >>outfile,str(student[0]),str(student[1]),"
" outfile.flush() #can't write more than 25KB at a time it seems print >>outfile,""" """ sys.exit(0)