Created
March 24, 2009 17:48
-
-
Save mrchrisadams/84254 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
def yql_name_hpricot(name) | |
# this method takes a place name, and returns the English name of the region it resides in. | |
# So 'Marnee La Valle Chessy' becomes 'Chessy', and 'London Kings Cross International' becomes 'London', and so on | |
require 'hpricot' | |
require 'open-uri' | |
# Use CGI library to escape out strange characters, which choke up Geoplanet | |
url_safe_name = CGI::escape(name) | |
yql = "http://query.yahooapis.com/v1/public/yql?" | |
doc = Hpricot.XML(open("#{yql}q=select%20locality1%20from%20geo.places%20where%20text%3D%22#{url_safe_name}%22")) | |
(doc/:"locality1").first.innerHTML | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment