Created
August 17, 2009 20:12
-
-
Save vanpelt/169347 to your computer and use it in GitHub Desktop.
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 'httparty' | |
| require 'cgi' | |
| units = Unit.all(:job_id => 1111, :golden => true).to_a | |
| units.each do |u| | |
| #Where u is an instance of Unit... | |
| q = u.data["full_address_gold"].join(" ") | |
| res = HTTParty.get("http://maps.google.com/maps/geo?q=#{CGI.escape(q)}&ue=utf8&sensor=false&key=ABQIAAAAo7WZCzZIkSblHMg0GJ-AwRTO9bHCf1xwbKWofRtvGHi3UueLXRRlU_wLzBzvBmEBRO_34kWbmaAngQ") | |
| p = res["Placemark"] | |
| if p && p.length == 1 && p[0]["AddressDetails"]["Accuracy"] > 6 | |
| u.data["full_address_gold"] = p[0]["address"] | |
| else | |
| puts "Failed #{q.inspect} ... #{res["Status"]["code"]}" | |
| end | |
| sleep(5) | |
| end | |
| units[0].data["full_address_gold"] | |
| => Does this look good? | |
| units.each {|u| u.save } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment