Permalink
Cannot retrieve contributors at this time
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?
snippets/umd-dining-balance/umd-dining-balance
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
38 lines (27 sloc)
1.11 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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. | |
# http://opensource.org/licenses/MIT | |
require "mechanize" | |
require "nokogiri" | |
URL = "https://login.umd.edu/cas/login?service=http://dsonline.umd.edu/dsbalance/" | |
abort("Usage: #{$PROGRAM_NAME} <username> <password>") if ARGV.length != 2 | |
username, password = ARGV.shift(2) | |
mech = Mechanize.new | |
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| | |
r.css("td").map(&:text).map(&:lstrip).join | |
end.reject { |e| e == "\u00A0" } | |
output.each { |e| puts e.sub(" : ", ": ") } |