Skip to content

Instantly share code, notes, and snippets.

@macks
Created August 25, 2017 08:23
Show Gist options
  • Save macks/4535d816e3bf0c24a15395f1444920ba to your computer and use it in GitHub Desktop.
Save macks/4535d816e3bf0c24a15395f1444920ba to your computer and use it in GitHub Desktop.
CEDEC 2017 のセッション情報を取得する
#!/usr/bin/env ruby
require 'open-uri'
require 'nokogiri'
require 'json'
sessions = []
%w(
http://cedec.cesa.or.jp/2017/session/schedule_0830/
http://cedec.cesa.or.jp/2017/session/schedule_0831/
http://cedec.cesa.or.jp/2017/session/schedule_0901/
).each do |url|
doc = Nokogiri::HTML(open(url))
uri = URI.parse(url)
date = doc.title[%r{^\d+/\d+}]
doc.search('ul.schedule_session_index > li').each do |li|
session = { date: date }
%i(ss_time_start ss_time_end room_number ss_style ss_title schedule_speaker).each do |klass|
session[klass] = li.at(".#{klass}").inner_text.strip.gsub("\u3000", ' ').gsub(/\s{2,}/, ' ')
end
genres = []
translation = false
li.search('.ss_spec > img').each do |img|
case img[:src]
when %r{/genre_icon/}
genres << File.basename(img[:src]).sub(/_.*$/, '')
when %r{/trans_sim_ja}
translation = true
end
end
session[:url] = (uri + li.at('.ss_title a')[:href]).to_s
session[:genres] = genres
session[:translation] = translation
session[:type] = li.at('.ss_ippr_icon > img')&.attr(:title)
session[:timeshift] = li.at('.timeshift-icon > img')[:title].end_with?('あり')
session[:ss_style].delete!('[]')
sessions << session
end
end
puts JSON.generate(sessions)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment