Downloading student assignment files from Blackboard as a single zip file saves a lot of timeÂ â€” you don’t have to individually open each “attempt”, download the file (renaming it in the process, so you don’t keep overwriting the previous file, since they are all named “Homework1.pdf” 😉 ), and then move on to the next one. Instead you get one convenient .zip file that contains all of the assignment files.
Unfortunately, Blackboard does some other things that make your life a bit more difficult. Once you unzip the file, you will find:
- The student files are renamed from filename.ext to assignmentname_username_attempt_datetime_filename.ext
- A text file is created for each student named assignmentname_username_attempt_datetime.txt even if the student has not entered any text data or comments.
Checking all of the text files to see if they really contain a comment and deleting those that don’t, and renaming all of the assignment files to username.ext so that I can start grading them 1 This process takes 15 minutes or more per assignment, which certainly lowers my enthusiasm for grading.
Today, I decided that I should write some code to automate this task. The time it would take to write the script would be recouped in only a few assignments. I decided to write the script in Python because I could easily see how to do the string manipulations. My shell scripting string manipulations are not as good. I would have to learn how to do the file system manipulations in Python, but I figured that would be relatively simple.
The first step is getting a list of all the files in the directory (leaving out all of the subdirectories)2:
onlyfiles = [ f for f in os.listdir(dir) if os.path.isfile(os.path.join(os.curdir,f)) ]
The next step is filtering that list to get just the .txt files:
txtfiles = [ f for f in onlyfiles if '.txt' in f ]
Then you can search the contents of the textfiles. You’ll notice that there are two characteristic phrases that indicate no text data and no comments. You can just delete the files that contain both of those:
for f in txtfiles: file = open(f) contents = file.read() file.close() if 'There are no student comments for this assignment' in contents and \ 'There is no student submission text data for this assignment.' in contents: os.remove(f) print('Deleted', f)
After refreshing the list of files to be just the remaining files, you can go about renaming the files. They all have _attempt_ embedded in their filename. Then you want to strip off everything up-to-and-including the first underscore, and from the second underscore up to the file extension. Then rename the file.
for f in onlyfiles: if '_attempt_' in f: first = f.find('_') # location of first underscore second = f.find('_',first+1) # location of second underscore extension = f[f.rfind('.'):] # get file extension newf = f[first+1:second] + extension os.rename(f, newf) print('Renamed', f, 'to', newf)
There are probably other features I can add, but this works well enough for now. Back to grading…
Full code is on GitHub here.
- I may still have to convert some of them to PDFs, if the students have not followed instructions, since I grade them by marking up the PDFs on my iPad. But that’s something I’ll tackle later. For my programming classes, I do that with my grading scripts which are still a work-in-progress. ↩
- http://stackoverflow.com/a/3207973 ↩