1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#!/usr/bin/perl
use strict;
use warnings;
use File::Slurp;
use Text::vFile::asData;
use Digest::MD5 qw(md5_hex);
use DateTime;
use CGI;
my $file = -e 'SystemsSupportRota' ? 'SystemsSupportRota' : '/usr/local/apache/htdocs/intranet/database/SystemsSupportRota';
=head1 NAME
rota_ical.cgi - scrape the SystemsSupportRota wiki page into ics
=head1 DESCRIPTION
=cut
sub make_event {
my $when = shift;
my $who = shift;
my $year = DateTime->now->year;
return unless $when =~ m{(\d+)\s*/\s*(\d+)};
my ($day, $month) = ($1, $2);
my $start = DateTime->new( year => $year, month => $month, day => $day );
my $end = $start->clone->add( days => 1 );
return {
type => 'VEVENT',
properties => {
SUMMARY => [ { value => "$who on call" } ],
DESCRIPTION => [ { value => "$when $who" } ],
DTSTART => [ { value => $start->ymd(''),
param => { VALUE => 'DATE' },
} ],
DTEND => [ { value => $end->ymd(''),
param => { VALUE => 'DATE' },
} ],
UID => [ { value => md5_hex( "$when $who" ),
} ],
},
};
}
my $cal = {
type => 'VCALENDAR',
properties => {
'X-WR-CALNAME' => [ { value => "Systems Rota" } ],
},
objects => [],
};
for (read_file( $file )) {
next if /^\s*$/;
/^\|(.*?)\|(.*)\|/ and do {
push @{ $cal->{objects} }, make_event( $1, $2 );
next;
};
# warn "unhandled line: $_";
}
print CGI->header('text/calendar');
print map "$_\n", Text::vFile::asData->generate_lines( $cal );
|