Skip to content

Instantly share code, notes, and snippets.

@dsummersl
Created November 1, 2016 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsummersl/2c1ce5b48af2d32c85fd11bee016d0a3 to your computer and use it in GitHub Desktop.
Save dsummersl/2c1ce5b48af2d32c85fd11bee016d0a3 to your computer and use it in GitHub Desktop.
require 'rake'
namespace :data do
require 'open-uri'
require 'csv'
task load_drains: :environment do
puts 'Downloading Drains... ... ...'
url = 'durham.csv'
csv_string = open(url).read
drains = CSV.parse(csv_string, headers: true)
puts "Downloaded #{drains.size} Drains."
drains.each do |drain|
# lat,lon,owner,status,type
# next unless ['Storm Water Inlet Drain', 'Catch Basin Drain'].include?(drain['type'])
lat = drain['lat']
lng = drain['lon']
thing_hash = {
name: drain['type'],
system_use_code: drain['type'],
lat: lat,
lng: lng,
}
thing = Thing.where(city_id: 'Durham').first_or_initialize
if thing.new_record?
puts "Updating thing #{thing_hash[:city_id]}"
else
puts "Creating thing #{thing_hash[:city_id]}"
end
thing.update_attributes!(thing_hash)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment