#!/usr/bin/perl -w use strict; use lib qw(lib); use Data::ICal::DateTime; use Data::ICal::Entry::Event; use DateTime; use DateTime::Span; use XML::RSS; my $ics = shift || "London.pm.ics"; $|++; # define our time range (because recurring events can be infinite) my $date1 = DateTime->now; my $date2 = DateTime->now->add( days => 14 ); my $span = DateTime::Span->from_datetimes( start => $date1, end => $date2 ); # get the (possibly memoized for speed) events my @events = events($ics, $span); # create the RSS file (version 1.0) my $rss = new XML::RSS( version => '1.0' ); $rss->channel( title => "EVENT CALENDAR", link => "URL TO EVENT CALENDAR", description => "EVENT CALENDAR", ); # sort all the events into order for (sort { $a->start->epoch <=> $b->start->epoch } @events ) { # make a start and end label my $times; $times = $_->start->month . "/" . $_->start->day; if ($_->start->hms ne "00:00:00") { my ($minute) = $_->start->minute; if ($minute < 10) { $minute = '0' . $minute; } $times .= " " . $_->start->hour . ":" . $minute; } elsif ($_->start->day != $_->end->day){ $times .= " - " . $_->end->month . "/" . $_->end->day; } else { } my $summ = $_->summary || ''; my $desc = $_->description || ''; my $foo = $_->properties; my $loc = $foo->{"location"}[0]->{"value"} || ''; my $title; if ($loc) { $title = "$times: $summ ($loc)"; } else { $title = "$times: $summ"; } $rss->add_item( title => $title, link => "URL TO EVENT CALENDAR", description => $desc, ) } print $rss->as_string; sub events { my ($ics, $span) = @_; my $cal = Data::ICal->new( filename => $ics ); my @events = $cal->events($span); return @events; } sub span_to_name { my $ics = shift; my $span = shift; my $start = ($span->start_is_open)? "infinite" : $span->start->epoch; my $end = ($span->end_is_open)? "infinite" : $span->end->epoch; return "$ics-$start-$end"; }