From owner-svn-src-user@FreeBSD.ORG Mon Feb 25 09:00:51 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 04DD4167; Mon, 25 Feb 2013 09:00:51 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id D58B17C6; Mon, 25 Feb 2013 09:00:50 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id r1P90o08003227; Mon, 25 Feb 2013 09:00:50 GMT (envelope-from rpaulo@svn.freebsd.org) Received: (from rpaulo@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id r1P90ovw003226; Mon, 25 Feb 2013 09:00:50 GMT (envelope-from rpaulo@svn.freebsd.org) Message-Id: <201302250900.r1P90ovw003226@svn.freebsd.org> From: Rui Paulo Date: Mon, 25 Feb 2013 09:00:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r247256 - user/rpaulo X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Feb 2013 09:00:51 -0000 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 +# 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