Bruins Schedule iCal Script

pudge on 2005-10-13T16:15:14

I fetched the CSV version of the Boston Bruins schedule, and then wrote this script to import it into iCal using Mac::Glue. Hooray.

Update: The CSV file has incorrect dates for when the time is past midnight, so it has games going from 10 p.m. on the 4th to 1 a.m. on the 4th. Oops. Also added quick DST calculation.

#!/usr/bin/perl

### first make empty "Bruins" calendar in iCal!

use strict; use warnings;

use Date::Parse;

use Mac::Glue ':all';

my $ical = new Mac::Glue 'iCal';

my $bcal = $ical->obj(calendar => whose(title => equals => 'Bruins')); my $bloc = location(end => $bcal);

my($dsts) = str2time('April 2 2006'); my($dste) = str2time('October 30 2005');

while () { next unless m{^(Boston Bruins (at|vs\.) ([^,]+)),((\d+)/(\d+)/(\d+),(\d+):(\d+):00 ([AP]M)),((\d+)/(\d+)/(\d+),(\d+):(\d+):00 ([AP]M)),}; my($summ, $start, $end) = ($1, $4, $11);

$start = str2time($start); $end = str2time($end); $end += 86400 if $start > $end;

my $adj = 3600 * ( ($start < $dsts && $start > $dste) ? 4 : 3 ); $_ -= $adj for ($start, $end);

# printf "%d : %s : %s : %s\n", $adj, $summ, scalar(localtime $start), scalar(localtime $end); # next;

$ical->make( new => 'event', at => $bloc, with_properties => { summary => $summ, start_date => $start, end_date => $end, } ); }

#Subject,StartDate,StartTime,EndDate,EndTime,Alldayevent,Reminderonoff,ReminderDate,ReminderTime,Description,Location,Priority,Private,Sensitivity,Showtimeas __END__ Boston Bruins vs. Montreal,10/5/2005,7:00:00 PM,10/5/2005,10:00:00 PM,FALSE,TRUE,10/5/2005,12:00:00 PM,,TD Banknorth Garden,Normal,TRUE,Normal,0 Boston Bruins at Buffalo,10/7/2005,8:00:00 PM,10/7/2005,11:00:00 PM,FALSE,TRUE,10/7/2005,4:00:00 PM,,Away,Normal,TRUE,Normal,0