Since Tobias just mentioned he has his festivals added to his wiki
(e.g. at http://wiki.tango.info/mul/Category:festivals) I thought it
would be fun to just parse all events in 2007 and create a calendar
from it. Easy, right?
Well... I am still in the process of doing so ;) Just wanted to express
my wish for a direct link to Tobias's festival link from the wiki
page, since that seems to be missing...
...will keep you posted how far I get.
require "rubygems"
require "mechanize"
require 'icalendar'
require 'date'
include Icalendar # Probably do this in your class to limit namespace
overlap
class TangoInfoExtractor < WWW::Mechanize
def process
cal = Calendar.new
user_agent_alias = 'Mac FireFox'
get "http://wiki.tango.info/mul/Category:festivals"
# page.links.each do |link|
# puts link.text
# end
page.links.with.href( %r{2007-12} ).each do |link|
puts link.href
begin
transact do
test = get link
content = (test/"#bodyContent")
festivalURL = (content/"p/a").inner_html
p festivalURL
festivalDescription = (content/"ul")
event = Event.new
s = link.text.scan(/[\d-]+/)
t = s[0].scan(/\d+/)
# if we only have 3 numbers it is a one day event
if t[3] == nil
event.start = DateTime.civil(t[0].to_i, t[1].to_i,
t[2].to_i)
event.end = DateTime.civil(t[0].to_i, t[1].to_i,
t[2].to_i)
# if we have 4 numbers it is a multi day event, but within
one month
elsif t[4] == nil
event.start = DateTime.civil(t[0].to_i, t[1].to_i,
t[2].to_i)
event.end = DateTime.civil(t[0].to_i, t[1].to_i,
t[3].to_i)
# if we have 5 numbers we have a multi day event spanning
multiple months
else
event.start = DateTime.civil(t[0].to_i, t[1].to_i,
t[2].to_i)
event.end = DateTime.civil(t[0].to_i, t[3].to_i,
t[4].to_i)
# don't worry about spanning years for now.
end
event.categories = ["tango", "festival"]
# Now with support for property parameters
event.url = festivalURL
event.summary = link.text
event.description = festivalDescription.inner_html
cal.add_event(event)
end
# Now we're back at the original page.
rescue => e
$stderr.puts "#{e.class}: #{e.message}"
end
end
# We can output the calendar as a string to write to a file,
# network port, database etc.
cal_string = cal.to_ical
puts cal_string
end
end
TangoInfoExtractor.new.process
You could probably run it via a cron job?
see the subcategories at:
http://wiki.tango.info/mul/Category:DEBER
I think: Date in page title, Location via category.
I have to think about a solution for repeating events. Before I have
no good idea for that I am unwilling to programm ics. I am just not
sure whether the wiki is the right thing.
--
Tobias Conradi
Rheinsberger Str. 18
10115 Berlin, Germany
http://info.tango.info http://eng.tango.info
http://festivals.tango.info http://videos.tango.info
http://wiki.tango.info