Skip to content

Instantly share code, notes, and snippets.

@mrchrisadams
Created March 24, 2009 17:48
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 mrchrisadams/84254 to your computer and use it in GitHub Desktop.
Save mrchrisadams/84254 to your computer and use it in GitHub Desktop.
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