Date: Mon, 25 Feb 2013 09:00:50 +0000 (UTC) From: Rui Paulo <rpaulo@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r247256 - user/rpaulo Message-ID: <201302250900.r1P90ovw003226@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: rpaulo Date: Mon Feb 25 09:00:49 2013 New Revision: 247256 URL: http://svnweb.freebsd.org/changeset/base/247256 Log: Parse anchor attributes. Modified: user/rpaulo/asiabsdcon.rb Modified: user/rpaulo/asiabsdcon.rb ============================================================================== --- user/rpaulo/asiabsdcon.rb Mon Feb 25 08:24:21 2013 (r247255) +++ user/rpaulo/asiabsdcon.rb Mon Feb 25 09:00:49 2013 (r247256) @@ -1,4 +1,28 @@ #!/usr/bin/env ruby +#- +# Copyright (c) 2013 Rui Paulo <rpaulo@FreeBSD.org> +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS O R +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. require 'rubygems' require 'open-uri' @@ -9,10 +33,12 @@ require 'ri_cal' debug = true require 'awesome_print' if debug +timetable = "http://2013.asiabsdcon.org/timetable.html" + if debug - doc = Nokogiri::HTML(File.open("Desktop/test.html")) + doc = Nokogiri::HTML(File.open("test.html")) else - doc = Nokogiri::HTML(open("http://2013.asiabsdcon.org/timetable.html")) + doc = Nokogiri::HTML(open(timetable)) end days = [] @@ -40,6 +66,7 @@ ap rooms if debug events = [] currentday = 0 doc.xpath("//div/table").each do |table| + # XXX fix entries that span multiple rows table.xpath("tbody/tr").each do |tr| time = tr.at("th").text.split("-") tstart = DateTime.parse(days[currentday] + " " + time[0]) @@ -50,14 +77,22 @@ doc.xpath("//div/table").each do |table| currentroom = 0 tr.xpath("td").each do |td| event = {} - event[:title] = td.search("a").text + if td.text == "-" or td.text == "Lunch" or + td.text == "Break" + next + end + anchor = td.search("a").first + if anchor == nil + event[:title] = td.text + else + event[:title] = anchor.text + event[:url] = timetable + anchor.attr("href") + end 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 + events.push(event) currentroom += 1 end end @@ -77,8 +112,11 @@ ics = RiCal.Calendar do |cal| calevent.dtstart = event[:tstart] calevent.dtend = event[:tend] calevent.location = event[:room] + if event[:url] + calevent.url = event[:url] + end end end end -print ics if debug +print ics
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201302250900.r1P90ovw003226>