Created
October 13, 2019 05:19
-
-
Save inaniwa3/509fbe34fe2f8a56c80f3937aeaf1678 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
#!/usr/bin/env ruby | |
require 'nokogiri' | |
# ("2015".."2019").each do |y| | |
# ("01".."12").each do |m| | |
# url = "https://www.tbsradio.jp/warai954/#{y}/#{m}/index.html" | |
# e = "curl -f #{url} -o ./html/#{y}_#{m}.html" | |
# puts e | |
# # `#{e}` | |
# end | |
# end | |
r = {} | |
Dir.glob('./html/*.html').sort.reverse.each do |path| | |
doc = Nokogiri::HTML(File.read(path)) | |
w = 1 | |
doc.xpath('//*[@id="best_bk"]/div/ul').each do |ul| | |
k = path[7..13] # yyyy_mm | |
v = [] | |
ul.xpath('.//li').each do |li| | |
winner = !li.xpath('.//*[@class="best_bk_ybtn"]|.//*[@class="best_ybtn"]').empty? | |
v << (winner ? 1 : 0) | |
end | |
next unless v.length >= 4 && v.length <= 6 && v.sum == 1 | |
k += "_#{w}" | |
r[k] = v | |
w += 1 | |
end | |
end | |
# pp r | |
s = [0, 0, 0, 0, 0] | |
r.each do |k, v| | |
next unless v.length == 5 | |
s = s.zip(v).map{|a, b| a + b} | |
end | |
p s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment