Skip to content

Instantly share code, notes, and snippets.

@ericfreese
Last active January 18, 2017 15:15
Show Gist options
  • Save ericfreese/67e125d145cde575db33ab3876cd17b3 to your computer and use it in GitHub Desktop.
Save ericfreese/67e125d145cde575db33ab3876cd17b3 to your computer and use it in GitHub Desktop.
Download all valid addresses for Boulder, CO
#!/usr/bin/env ruby
require 'csv'
require 'active_support/all'
OUTPUT_FILENAME = 'boulder_addresses.txt'
if !FileTest.exist?("Owner_Address.csv")
puts 'downloading address data...'
`wget http://assessor.boco.solutions/ASR_PublicDataFiles/Owner_Address.csv`
else
puts 'address data already downloaded...'
end
puts 'formatting addresses...'
addresses = CSV.open("Owner_Address.csv", headers: true).map do |r|
street_address = [
r["str_num"],
r["str_pfx"],
r["str"].try(:titleize),
r["str_sfx"].try(:titleize)
].compact.reject(&:empty?).join(' ')
[street_address, r["city"].try(:titleize), "CO"].compact.reject(&:empty?).join(', ')
end
puts 'filtering addresses...'
filtered_addresses = addresses.
uniq.
select{ |l| l.include?("Boulder, CO") }.
sort_by{ |l| l.gsub(/\d+ /, '') }
puts 'writing to file...'
File.open(OUTPUT_FILENAME, "w") do |f|
filtered_addresses.each do |l|
f.puts(l)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment