Skip to content

Instantly share code, notes, and snippets.

@hatone
Created October 21, 2012 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hatone/5b168fc72faf343a370f to your computer and use it in GitHub Desktop.
Save hatone/5b168fc72faf343a370f to your computer and use it in GitHub Desktop.
アレとコレが一致するか?
- "Fantaisieantaisie Impromptu"
- "Quasi una Fantasia"
- "Klaviersonate Nr.11 A‐dur"
require "rubygems"
require "net/http"
require "uri"
require "json"
require "pp"
require 'yaml'
require 'cgi'
GOOGLE_KEY = ""
categories1 = YAML.load_file("category1.yml")
categories2 = YAML.load_file("category2.yml")
api_path = "http://ajax.googleapis.com/ajax/services/search/web"
api = URI.parse(api_path)
headers = {'Referer' => 'http://hatone.info/'}
categories1.each do |category1|
max_count = 0
category = ""
categories2.each do |category2|
data = "?v=1.0&key=#{GOOGLE_KEY}&q="+ CGI.escape(category1.to_s+" is similar to "+category2.to_s)
apicall = Net::HTTP.new(api.host)
response = apicall.get2(api.path + data, headers)
data = JSON.parse(response.body)
return exit if data['responseStatus'] == 403
count = data['responseData']['cursor']['estimatedResultCount']
count = count.to_i
if max_count < count
max_count = count
category = category2.to_s
end
end
pp category1 + " is " + category
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment