Skip to content

Instantly share code, notes, and snippets.

@hatone
Created Oct 21, 2012
Embed
What would you like to do?
アレとコレが一致するか?
- "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