-
-
Save hatone/5b168fc72faf343a370f 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
- Chopin |
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
- "Fantaisieantaisie Impromptu" | |
- "Quasi una Fantasia" | |
- "Klaviersonate Nr.11 A‐dur" |
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
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