Last active
June 14, 2017 07:04
-
-
Save mateoclarke/931d0a3fdebb845d1caab86566b7b0fd to your computer and use it in GitHub Desktop.
Sum each CoA Department line items from General Fund
This file contains hidden or 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
require 'httparty' | |
require 'active_support' | |
include ActiveSupport::NumberHelper | |
LIMIT = 7000 | |
DEPARTMENTS = [ | |
"Municipal Court", | |
"Animal Services", | |
"Fire", | |
"Austin Public Library", | |
"Austin Public Health", | |
"Development Services", | |
"Emergency Medical Services", | |
"Human Resources", | |
"Neighborhood Housing and Community Development", | |
"Nondepartmental Revenue/Expenses", | |
"Parks and Recreation", | |
"Planning and Zoning", | |
"Police", | |
"Social Service Contracts" | |
] | |
DEPARTMENTS.each do |department| | |
url = "https://data.austintexas.gov/resource/e622-gceg.json?DEPARTMENT_NAME=#{department}&$limit=#{LIMIT}" | |
response = HTTParty.get(url) | |
puts "warning, feed me more data" if response.parsed_response.count >= LIMIT | |
# Sum the budget values for each line item under the department | |
budget_value = response.parsed_response.reduce(0) do |memo, item| | |
item["budget"].to_i + memo | |
end | |
puts "#{department} 2016-2017 Budget from General Fund: #{number_to_delimited(budget_value)} | |
from #{number_to_delimited(response.parsed_response.count)} line item records." | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment