Skip to content

Instantly share code, notes, and snippets.

@lucca65
Created December 16, 2015 20:58
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 lucca65/9f46f8f79aa8b6d415bb to your computer and use it in GitHub Desktop.
Save lucca65/9f46f8f79aa8b6d415bb to your computer and use it in GitHub Desktop.
# encoding: UTF-8
require 'rubygems'
require 'csv'
require 'geocoder'
ips = CSV.read('ip.csv')
total = ips.length
decoded_ips = []
ips.each_with_index do |ip, index|
decoded = Geocoder::search(ip.first).first
puts "Decoded #{index} OF #{ips.length}"
row = [ip.first, decoded.data['country_name'], decoded.data['region_name'], decoded.data['city']]
decoded_ips << row
end
CSV.open 'result.csv', 'wb' do |file|
decoded_ips.each { |row| file << row }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment