Created
January 9, 2018 02:04
-
-
Save cameronbarker/cc584eb38499f539ed10e1a5392572bc to your computer and use it in GitHub Desktop.
This file contains 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
arr_of_arrs = CSV.read("/Users/cameronbarker/Desktop/reading.csv") | |
["Timestamp", | |
"Full name of Ninja", | |
"Original Address", | |
"Address", | |
"City", | |
"State", | |
"Zip Code", | |
"Country", | |
"Country Code", | |
"Email Address", | |
"Notes or a place to say Hi!"] | |
arr_of_arrs.shift | |
arr_of_arrs.shift | |
objs = arr_of_arrs.map do |t| | |
next if t.first.nil? | |
o = OpenStruct.new | |
o.timestamp = t[0] | |
o.name = t[2] | |
o.original_address = t[4] | |
o.address = t[4] | |
o.city = t[5] | |
o.state = t[6] | |
o.zipcode = t[7] | |
o.country = t[8] | |
o.country_code = t[9] | |
o.email = t[10] | |
o.note = t[11] | |
o | |
end | |
# build geo | |
objs.each do |o| | |
next if o.try(:city).present? | |
c = Geocoder.search(o.address) | |
c = c.first | |
next if c.nil? || c.city.nil? || c.state.nil? | |
o.address = "#{c.street_number.to_s} #{c.route.to_s}" | |
o.city = c.city | |
o.state = c.state | |
o.zipcode = c.postal_code | |
o.country = c.country | |
o.country_code = c.country_code | |
sleep 0.5 | |
print '.' | |
end | |
csv_arr = objs.map do |o| | |
arr = [] | |
arr << o.timestamp | |
arr << o.name | |
arr << o.original_address | |
arr << o.address | |
arr << o.city | |
arr << o.state | |
arr << o.zipcode | |
arr << o.country | |
arr << o.country_code | |
arr << o.email | |
arr << o.note | |
arr | |
end | |
DirectUpload.csv(csv_arr, 'ReadingNinja.csv') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment