Skip to content

Instantly share code, notes, and snippets.

@graybill
Created April 7, 2011 02:05

Revisions

  1. graybill created this gist Apr 7, 2011.
    32 changes: 32 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    require 'csv'

    def coordinates(addr)
    include Geokit::Geocoders
    res=MultiGeocoder.geocode(addr)
    res.ll
    end

    namespace :import do
    desc 'Parse CSV files and import into the database'

    task :non_store_csv => :environment do
    file = "/Users/admin/code/tubfinder/public/data/nonstore.csv"
    CSV.foreach file do |row|
    addr = row[1] + " " + row[2] + "," + row[5]
    loc = coordinates(addr)
    p loc
    l = Location.new(
    :name => row[0],
    :address => addr,
    :loc_type => 'bar',
    :zipcode => row[5]
    )
    l.loc = loc
    l.save

    p l

    end
    p Location.all.count
    end
    end