Skip to content

Instantly share code, notes, and snippets.

@aitor
Created January 27, 2010 12:05
Show Gist options
  • Save aitor/287782 to your computer and use it in GitHub Desktop.
Save aitor/287782 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'icalendar'
require 'date'
include Icalendar
class IrekiaCalendar
BASE_URL = "http://irekia.euskadi.net/es/dept/all/events?archive=f"
def events
document.search('//div[@class="events_list"]/div[@class="news_row"]//td[@class="title"]').map { |p|
p.content.split("\n").map{|st| st.strip}.delete_if{|s| s == ""}
} rescue []
end
def document
@document ||= Nokogiri::HTML(open(BASE_URL).read)
end
def calendar
cal = Calendar.new
self.events.each do |e|
puts "Adding ... " + e.inspect if $DEBUG
cal.event do
dtstart e[1]
summary e[0]
description e[0]
klass e[-1]
end
end
cal
end
end
cal = IrekiaCalendar.new.calendar
puts cal.to_ical if $DEBUG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment