#!/usr/bin/perl use XML::DOM; use strict; # get the first element under a node of the given tag # @param node: node under which to look for elements # @param tag: the tage to look for # @return: first element under node with the given tag sub subvalue($$) { my ($class, $tag) = @_; return value($class->getElementsByTagName($tag)->item(0)); } # get the node value of the first child of a given node # @param node: whose child to use # @return: node value of given node's first child sub value($) { my ($class) = @_; if (undef == $class) { return undef; } my $child = $class->getFirstChild(); if (undef == $child) { return undef; } return $child->getNodeValue(); } print <new(); my $doc = $parser->parsefile($ARGV[0]); my @events = $doc->getElementsByTagName("eventitem"); foreach my $event (@events) { my $date = $event->getAttribute("date"); my $time = $event->getAttribute("time"); my $talk_title = $event->getAttribute("title"); $talk_title =~ s/[:;,]//g; my $room = $event->getAttribute("room"); my $short = subvalue($event, "short"); $short =~ s/[:;,]//g; my $abstract = $event->getElementsByTagName("abstract")->item(0)->toString(); my $ical_date = `date -d"$date" +%Y%m%d`; chomp $ical_date; my ($ical_start, $ical_end); if ($time =~ /(.*)-(.*)/) { $ical_start = ical_time($1); $ical_end = ical_time($2); } else { $ical_start = ical_time($time); $ical_end = ical_time("$time + 1 hour"); } $abstract =~ s///; $abstract =~ s/<\/abstract>//; $abstract =~ s/\n/ /sg; my $ical_abstract = "\"$abstract\""; sub ical_time { my ($ds) = @_; my $d = `date -d"$ds" +\%H\%M\%S`; chomp $d; return $d; } print <$talk_title -- $short DESCRIPTION:$ical_abstract END:VEVENT END_OF_EVENT } print "END:VCALENDAR\n";