Last active
July 26, 2016 08:02
-
-
Save imaizume/341fa73ca7b29c46d0d788afc8594c44 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
require 'nokogiri' | |
require 'open-uri' | |
require 'pp' | |
require 'matrix' | |
unless ARGV.length > 0 | |
puts "Please pass tonton's URL to the argument." | |
exit | |
end | |
URL_TONTON = 'http:tonton.amaneku.com/list.php' | |
PATTERN_TONTON = /http:\/\/tonton\.amaneku\.com\/list\.php/ | |
SYMBOL_PRESENT = '●' | |
url = ARGV[0] | |
unless url.match PATTERN_TONTON | |
puts "URL does not match tonton page pattern! : #{URL_TONTON}" | |
exit | |
end | |
doc = Nokogiri::HTML(open(url, "r:Shift_JIS")) | |
schedules = [] | |
members = doc.css("#usercommentlist .user-name label").map { |c| c.content } | |
dates = [] | |
doc.css('.schedulelist').each do |day| | |
dates.push day.css('td.user')[0].content | |
# matched = date.match(/(\d{4})\/(\d{1,2})\/(\d{1,2})/) | |
# y, m, d = matched[1], matched[2], matched[3] | |
# date = "#{y}#{m}#{d}" | |
schedule = {} | |
presenses = day.css('.tablestyle-03 .list').map do |list| | |
user= list.css('.user span')[0].content | |
presense = list.css('.timeline span[id^="mtgmembertime_"]').map do |c| | |
c['title'] == SYMBOL_PRESENT ? 1 : 0 | |
end | |
schedule[user] = presense | |
# puts "#{user}:#{presense}" | |
end | |
schedules.push schedule | |
end | |
times = (6..29.5).step(0.5).to_a | |
labels = dates.product(times).collect { |set| set.join "_" } | |
total = members.map do |member| | |
total_presense = [] | |
schedules.each do |schedule| | |
total_presense.concat schedule[member] | |
end | |
total_presense | |
end | |
total = total.transpose | |
scores = total.map { |row| row.inject :+ } | |
e1 = labels.to_enum | |
e2 = scores.to_enum | |
result = [] | |
loop do | |
result << "#{e1.next} #{e2.next}" | |
end | |
puts result |
Output
> ruby tonton-count.rb " http://tonton.amaneku.com/list.php?id=(your tonton id)" | sort -nk2
...
2016/8/9(火)_10.0 11
2016/8/9(火)_10.5 11
2016/8/9(火)_11.0 11
2016/8/9(火)_11.5 11
2016/8/9(火)_12.0 11
2016/8/9(火)_12.5 11
2016/8/9(火)_13.0 11
2016/8/9(火)_13.5 11
2016/8/9(火)_14.0 11
2016/8/9(火)_14.5 11
2016/8/9(火)_15.0 11
2016/8/9(火)_15.5 11
2016/8/9(火)_16.0 11
2016/8/9(火)_16.5 11
2016/8/9(火)_20.0 11
2016/8/9(火)_20.5 11
2016/8/9(火)_21.0 11
2016/8/9(火)_21.5 11
2016/8/5(金)_18.0 12
2016/8/5(金)_18.5 12
2016/8/5(金)_19.0 12
2016/8/5(金)_21.5 12
2016/8/6(土)_12.0 12
2016/8/6(土)_12.5 12
2016/8/6(土)_13.0 12
2016/8/6(土)_13.5 12
2016/8/6(土)_14.0 12
2016/8/6(土)_14.5 12
2016/8/5(金)_19.5 13
2016/8/5(金)_20.0 13
2016/8/5(金)_20.5 13
2016/8/5(金)_21.0 13
2016/8/6(土)_10.0 13
2016/8/6(土)_10.5 13
2016/8/6(土)_11.0 13
2016/8/6(土)_11.5 13
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
ruby tonton-count.rb " http://tonton.amaneku.com/list.php?id=(your tonton id)"