Skip to content

Instantly share code, notes, and snippets.

@jeffrydegrande
Created August 29, 2009 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffrydegrande/177610 to your computer and use it in GitHub Desktop.
Save jeffrydegrande/177610 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'open-uri'
require 'nokogiri'
require 'icalendar'
require 'date'
class RailsSummit
include Icalendar
def initialize
@doc = Nokogiri::HTML(open('http://www.railssummit.com.br/pt-BR/schedule'), nil, 'UTF-8')
@cal = Calendar.new
parse!
end
def parse!
@doc.css('table.programacao').each_with_index do |day, index|
date = Date.parse("2009/10/#{13 + index}")
day.search('tr').each do |tr|
cells = tr.search('td')
next if cells.count == 0
time = cells.shift.content.strip
first, second = cells
if first['colspan'].to_i == 2
add_event(date, time, first.content.strip)
else
add_event(date, time, "Sala A: #{first.content.strip}" )
add_event(date, time, "Sala B: #{second.content.strip}" )
end
end
end
end
def to_s
@cal.to_ical
end
private
def add_event(date, time, summary)
from, junk, to = time.split
event = Event.new
event.start = DateTime.parse("#{date} #{from}")
event.end = DateTime.parse("#{date} #{to}")
event.summary = summary
event.description = summary
@cal.add_event(event)
end
end
puts RailsSummit.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment