Created
December 11, 2010 00:17
-
-
Save mhorbul/737021 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
#!/bin/env ruby | |
require 'open-uri' | |
require 'json' | |
require 'uri' | |
u='http://ajax.googleapis.com/ajax/services/search/local' | |
q="v=1.0&key=#{ENV['GOOGLE_API_KEY']}&mrt=localonly&rsz=8&sll=32.899594,-117.198722&q=food" | |
q << URI.encode(" #{ARGV[0]}") unless ARGV.empty? | |
begin | |
places = (1..100).to_a.shuffle.shift(10).reduce([]) do |r,s| | |
d=JSON.parse(open(u + "?" + q + "&start=#{s}").read)["responseData"] | |
next r if d.nil? | |
r + d["results"].map { |p| [p["titleNoFormatting"], p["addressLines"].join(", ")]} | |
end | |
end while places.nil? || places.empty? | |
puts "TOTAL places found: #{places.size}" | |
puts "SELECTED place: #{places.shuffle.first.inspect}" | |
__END__ | |
# Usage: | |
# export GOOGLE_API_KEY=<YOUR-GOOGLE-API-KEY-HERE> | |
# ./food-place-picker <cuisine> | |
# | |
# Example: | |
# ./food-place-picker indian | |
# ./food-place-picker asian | |
# | |
# Results: | |
# TOTAL places found: 8 | |
# SELECTED place: ["Vignesh Foods", "Mira Mesa Boulevard, San Diego, CA"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment