Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
executable file 50 lines (39 sloc) 1.22 KB
#!/usr/bin/env ruby
# frozen_string_literal: true
# umd-arrest-ledger.rb
# Author: William Woodruff
# ------------------------
# Fetch UMD arrest records for the given year and dump them as JSON.
# ------------------------
# This code is licensed by William Woodruff under the MIT License.
require "open-uri"
require "nokogiri"
require "json"
URL = "<year>d"
year = ARGV.shift.to_i
abort("Usage: #{$PROGRAM_NAME} <year>") if year.nil?
# ledgers before 11/2010 used a different format
unless year.between?(2010,
abort("Data is only available between 2010 and the current year.")
data = {}
url = URL % { year: year }
html = Nokogiri::HTML(open(url).read)
trs = html.css("table").first.css("tr")
trs.shift # remove the description <tr>
trs.each_slice(2) do |tr0, tr1|
# i am not proud of this.
entry = tr0.css("td").to_a.concat(tr1.css("td").to_a).map(&:text).map(&:strip)
data[entry[0]] = {
arrest_time: entry[1],
case_number: entry[2],
age: entry[3],
race: entry[4],
sex: entry[5],
charge: entry[6],
end"#{year}.json", "w") do |file|