Skip to content
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Cannot retrieve contributors at this time
executable file 38 lines (27 sloc) 1.11 KB
#!/usr/bin/env ruby
# frozen_string_literal: true
# umd-dining-balance.rb
# Author: William Woodruff
# ------------------------
# Fetch UMD dining plan balance data for a given student, by Directory ID.
# Uses Mechanize and Nokogiri.
# ------------------------
# This code is licensed by William Woodruff under the MIT License.
require "mechanize"
require "nokogiri"
URL = ""
abort("Usage: #{$PROGRAM_NAME} <username> <password>") if ARGV.length != 2
username, password = ARGV.shift(2)
mech =
page = mech.get(URL)
form = page.forms.first
form.field_with(name: "username").value = username
form.field_with(name: "password").value = password
html = Nokogiri::HTML(mech.submit(form).body)
abort("Fatal: Failed to login through CAS. Check your credentials.") if html.css("table").empty?
table = html.css("table").first.css("table")[1]
output = table.css("tr").map do |r|
end.reject { |e| e == "\u00A0" }
output.each { |e| puts e.sub(" : ", ": ") }