Skip to content

Instantly share code, notes, and snippets.

@kmlawson
Last active October 23, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmlawson/99747f2b7f9606fdedcc to your computer and use it in GitHub Desktop.
Save kmlawson/99747f2b7f9606fdedcc to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Rename and save this as fbsetup.rb, and add a fbsetup alias to your bash setup to point to this script
# This script is to designed to be run from the command line within a directory where you have a list of student assignments you will mark.
# The command, to be run in the directory of the target feedback form takes the format of:
# fbsetup [modulename] [assessmentname-one-word] [duedate-year-month-day]
# Example:
# fbsetup 3335 Short-Essay-1 2015-10-20
# It will:
# 1. The student assignments downloaded from MMS have the student number as the first 9 characters. It will grab these first 9 characters and assume they are the student number
# 2. Create new blank feedback forms (give this script the path below) for each student assessment file, prefixed with the student number, assessment name and current date.
# 3. Open each of these feedback forms, and enter in the appropriate studennt number (mnum), the module code (mcode), the due date (ddue), and the current date (date) in the appropriate places, assuming that the source feedback form has Microsoft Word bookmarks with the names listed above in the parentheses.
# Note: There is not error catching here.
require 'date'
# You will need to have installed the docx gem for Ruby, with 'gem install docx'
require 'docx'
modulename="MO"+ARGV[0] # Our module names have MO as a prefix
assessment=ARGV[1] # Needs to be a single word
duedate=ARGV[2]
todaydate=Date.today.strftime("%F") # Year-Month-Day
# This is the path to the feedback form that will be used, copied, and modified appropriately for each student assessment (requires the bookmarks mnum, mcode, ddue, and date):
feedbackform = '[enter the path to your feedback form.docx here]'
Dir.glob('*').each do |fname|
studentnumber=fname[0..8]
doc = Docx::Document.open(feedbackform)
doc.bookmarks['mnum'].insert_text_after(studentnumber)
doc.bookmarks['mcode'].insert_text_after(modulename)
doc.bookmarks['ddue'].insert_text_after(duedate)
doc.bookmarks['date'].insert_text_after(todaydate)
doc.save(Dir.pwd+'/'+studentnumber+'-Feedback-'+assessment+'-'+todaydate+'.docx')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment