Created
November 1, 2016 20:39
-
-
Save dsummersl/2c1ce5b48af2d32c85fd11bee016d0a3 to your computer and use it in GitHub Desktop.
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 '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