Created
April 25, 2017 20:46
-
-
Save jamescgibson/d8946ec714270cd2ed0b990301c7acb4 to your computer and use it in GitHub Desktop.
geocode_ip_csv
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
# Take a .csv file with IP addresses in a single column, and create a new file with the ip addresses | |
# and their associated ZIP codes | |
# Requires: Ruby, geocoder (gem install geocoder once ruby is installed | |
# Requies: File with ip addresses called ips.csv | |
require 'geocoder' | |
require 'csv' | |
ips = CSV.read("ips.csv").flatten | |
CSV.open("ip_output.csv", "w+") do |csv| | |
ips.each do |ip| | |
zip = Geocoder.search(ip).first.data["zip_code"] | |
csv << [ip, zip] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment