-
-
Save asonas/0acb82883dcf0a8bbf4f to your computer and use it in GitHub Desktop.
アレとコレが一致するか?
This file contains hidden or 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 hidden or 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 hidden or 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 "net/http" | |
| require "uri" | |
| require "json" | |
| require "pp" | |
| require "yaml" | |
| require "cgi" | |
| GOOGLE_KEY = "" | |
| composer_list = YAML.load_file("composers.yml") | |
| music_list = YAML.load_file("musics.yml") | |
| api_path = "http://ajax.googleapis.com/ajax/services/search/web" | |
| api = URI.parse(api_path) | |
| headers = { :Referer => "http://hatone.info/" } | |
| composer_list.each do |composer| | |
| max_count = 0 | |
| category = "" | |
| music_list.each do |music| | |
| query = CGI.escape("#{composer} is similar to #{music}") | |
| data = "?v=1.0&key=#{GOOGLE_KEY}&q=#{query}" | |
| 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 | |
| # result_count = ... | |
| # if max_count < result_count | |
| if max_count < count | |
| max_count = count | |
| category = music | |
| end | |
| end | |
| pp composer + " is " + category | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
to_sが頻発してたけど多分いらないと思ったので削除return exit if data['responseStatus'] == 403と、一行で書く(リーダブルコードより)