svn commit: r247253 - user/rpaulo
Rui Paulo
rpaulo at FreeBSD.org
Mon Feb 25 08:08:14 UTC 2013
Author: rpaulo
Date: Mon Feb 25 08:08:13 2013
New Revision: 247253
URL: http://svnweb.freebsd.org/changeset/base/247253
Log:
Add a script to convert the HTML schedule of AsiaBSDCon to a Calendar file.
Added:
user/rpaulo/asiabsdcon.rb
Added: user/rpaulo/asiabsdcon.rb
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ user/rpaulo/asiabsdcon.rb Mon Feb 25 08:08:13 2013 (r247253)
@@ -0,0 +1,84 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'open-uri'
+require 'nokogiri'
+require 'tzinfo'
+require 'ri_cal'
+
+debug = true
+require 'awesome_print' if debug
+
+if debug
+ doc = Nokogiri::HTML(File.open("Desktop/test.html"))
+else
+ doc = Nokogiri::HTML(open("http://2013.asiabsdcon.org/timetable.html"))
+end
+
+days = []
+rooms = []
+
+# Find all the days
+doc.xpath("//h2").each do |h2|
+ day = h2.text.match("(\\(.*\\))")
+ if day != nil
+ days.push(day.to_s[/[^()]+/])
+ end
+end
+ap days if debug
+
+# Find all the rooms
+doc.xpath("//div/table/thead/tr/th").each do |th|
+ room = th.text
+ if room.match("Room") and rooms.index(room) == nil
+ rooms.push(room)
+ end
+end
+ap rooms if debug
+
+# Find all the events
+events = []
+currentday = 0
+doc.xpath("//div/table").each do |table|
+ table.xpath("tbody/tr").each do |tr|
+ time = tr.at("th").text.split("-")
+ tstart = DateTime.parse(days[currentday] + " " + time[0])
+ tend = DateTime.parse(days[currentday] + " " + time[1])
+ tstart.set_tzid("Asia/Tokyo")
+ tend.set_tzid("Asia/Tokyo")
+
+ currentroom = 0
+ tr.xpath("td").each do |td|
+ event = {}
+ event[:title] = td.search("a").text
+ event[:person] = td.search("i").text.split(" (eml")[0]
+ event[:tstart] = tstart
+ event[:tend] = tend
+ event[:room] = rooms[currentroom]
+ if event[:title] != ""
+ events.push(event)
+ end
+ currentroom += 1
+ end
+ end
+ currentday += 1
+end
+ap events if debug
+
+# Build the Calendar file
+ics = RiCal.Calendar do |cal|
+ events.each do |event|
+ cal.event do |calevent|
+ summary = event[:title]
+ if event[:person]
+ summary += " - " + event[:person]
+ end
+ calevent.summary = summary
+ calevent.dtstart = event[:tstart]
+ calevent.dtend = event[:tend]
+ calevent.location = event[:room]
+ end
+ end
+end
+
+print ics if debug
More information about the svn-src-user
mailing list