Created
June 25, 2014 02:52
-
-
Save spara/bbb79c7df2a3272b1cae to your computer and use it in GitHub Desktop.
geocode texas beverage tax receipts
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 'rubygems' | |
require 'cgi' | |
require 'net/http' | |
require 'open-uri' | |
require 'json' | |
file = File.open('bev01-22.tsv').read | |
data = Array.new | |
base_url = 'http://www.datasciencetoolkit.org/maps/api/geocode/json?sensor=false&address=' | |
file.each_line do |line| | |
row = line.split("\t").map(&:strip) | |
address = CGI.escape([row[2],row[3],row[4],row[5]].join(',')) | |
uri = base_url + address | |
response = JSON.parse(URI.parse(uri).read) | |
row << response["results"][0]["geometry"]["location"]["lng"] | |
row << response["results"][0]["geometry"]["location"]["lat"] | |
data << row | |
end | |
out = File.new("bev01-22_out.tsv", 'w') | |
data.each do |d| | |
out.puts(d.join("\t")) | |
end | |
out.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment