Skip to content

Instantly share code, notes, and snippets.

@chrismetcalf
Created June 20, 2013 21:09
Show Gist options
  • Save chrismetcalf/5826671 to your computer and use it in GitHub Desktop.
Save chrismetcalf/5826671 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#
require 'httparty'
require 'json'
results = HTTParty.get("http://data.cityofchicago.org/api/search/views.json?limitTo=TABLES")
# Category -> [ Dataset, Dataset ]
by_categories = Hash.new { |h,k| h[k] = Array.new }
results["results"].each do |dataset|
dataset = dataset["view"]
size = dataset["columns"].collect { |c| c["cachedContents"]["null"] + c["cachedContents"]["non_null"] }.max
by_categories[dataset["category"]] << {
"url" => "https://data.cityofchicago.org/d/#{dataset["id"]}",
"name" => dataset["name"],
"size" => size,
"value" => 42 # Not sure how this is calculated
}
end
# Formulate the final hash
output = {
"name" => "Chicago Data Portal",
"children" => by_categories.collect { |cat,ds| { "name" => cat, "children" => ds } }
}
puts JSON.pretty_generate(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment