#! /usr/bin/perl # $Id: mksched-vcs.pl,v 1.1 2006/10/03 19:48:36 jzap Exp $ &main; exit; sub main { &init; &read_files; print "BEGIN:VCALENDAR\n", "VERSION:1.0\n", "PRODID:larry\@claritycoaching.com\@nhl.jzap.com\n"; &do_games; print "\n", "END:VCALENDAR\n"; } sub read_files { open F, "sched.txt"; while( ) { next unless /^sharks/i; push @sched, $_; } close F; $ngm = @sched; open F, "sched-tv.txt"; while( ) { s/\s+$//; split /\s*\t\s*/; next unless $_[ 1] =~ /^[0-9]+$/; next unless @_ >= 5; $sched_tv[ $ntv++] = $_[ 5]; } close F; $ntv = @sched_tv; die "ngm=$ngm ntv=$ntv not equal" unless $ngm == $ntv; } sub timeString { my ($date, $time, $offset) = @_; my ($MM, $DD, $YYYY) = split( /\//, $date); my ($hh, $mm, $ss, $ampm) = split( /[ :]+/, $time); $hh = 0 if $hh == 12; # 0 <= $hh <= 11 $hh += 12 if $ampm =~ /pm/i; # 0 <= $hh <= 23 # add offset $mm += $offset; while($mm >= 60) { $hh++; $mm -= 60; } while($mm < 0) { $hh--; $mm += 60; } # standard time starts 2006 Oct 29, Sunday # daylight savings time starts 2007 March 11, Sunday $is_std_time = $MM == 10 && $DD >= 29 || $MM > 10 || $MM < 3 || $MM == 3 && $DD < 11 || 0; # convert pst/pdt to gmt $hh += 8; # pst $hh -= 1 unless $is_std_time; $mday_max = $mday_max[ $MM]; $mday_max += 1 if $MM == 2 && $YYYY % 4 == 0; while( $hh >= 24) { $hh -= 24; $DD += 1; if( $DD > $mday_max) { $DD = 1; $MM += 1; if( $MM > 12) { $MM = 1; $YYYY += 1; } } } while( $hh < 0) { $hh += 24; $DD -= 1; if( $DD == 0) { $DD = $mday_max; $MM -= 1; if( $MM == 0) { $MM = 12; $YYYY -= 1; } } } $YYYYMMDD = sprintf( "%04d%02d%02d", $YYYY, $MM, $DD); $hhmmss = sprintf( "%02d%02d%02d", $hh, $mm, $ss); return "${YYYYMMDD}T${hhmmss}Z"; } sub do_games { $duration_min = 150; # game length (150m = 2h30m) $alarm_min = -90; # pre-game pop-up reminders # $game_num = 1; # includes pre-season games # @game_abc = qw( A B C); # pre-season game designations $game_num = 1; # does not include pre-season games # @game_abc = qw( A B C); # pre-season game designations for( $i = 0; $i < @sched; $i++) { $_ = $sched[ $i]; ($teams, $date, $time) = split /\s*\t\s*/; $teams =~ s/vs[.]/vs /i; ($sharks, $atvs, $opponent) = split( ' ', $teams, 3); $opponent =~ s/[ .]+/_/g; $start = timeString($date, $time, 0); $end = timeString($date, $time, $duration_min); $alarm = timeString($date, $time, $alarm_min); # get team names $opp_lcase = $opponent; $opp_lcase =~ tr/A-Z/a-z/; $opp_name = $team_name{ $opp_lcase}; $opp_city = $team_city{ $opp_lcase}; if( $atvs =~ /vs/i) { $game_str = $game_num <= @game_abc ? sprintf( "Game %s: ", $game_abc[ $game_num++ - 1]) : sprintf( "Game %d: ", $game_num++ - @game_abc); $sjs = 'San Jose Sharks'; $san_abbr = 'Sharks'; $av = 'v'; $location = 'Shark Tank'; $alarmStr = "DALARM:${alarm}\n"; } else { $game_str = ''; $sjs = 'San Jose Sharks'; $san_abbr = 'Sharks'; $av = '@'; $location = $opp_city; $alarmStr = ""; } $tv = @sched_tv[ $i]; $location .= " ($tv)" if length $tv > 0; print "\n", "BEGIN:VEVENT\n", "SUMMARY:$san_abbr $av $opp_name\n", "DESCRIPTION:$game_str $sjs $atvs $opp_city $opp_name\n", "DTSTART:${start}\n", "DTEND:${end}\n", "LOCATION:$location\n", "UID:SanJoseSharks${start}\n", $alarmStr, "END:VEVENT\n"; } } sub init { # maximum day of each month # [0]=0, [1..12]=max @mday_max = ( 0, # jan feb mar apr 31, 28, 31, 30, # may jun jul aug 31, 30, 31, 31, # sep oct nov dec 30, 31, 30, 31, ); %team_name = ( 'anaheim' => 'Mighty Ducks', 'atlanta' => 'Thrashers', 'boston' => 'Bruins', 'buffalo' => 'Sabres', 'carolina' => 'Hurricanes', 'columbus' => 'Blue Jackets', 'calgary' => 'Flames', 'chicago' => 'Blackhawks', 'colorado' => 'Avalanche', 'dallas' => 'Stars', 'detroit' => 'Red Wings', 'edmonton' => 'Oilers', 'florida' => 'Panthers', 'los_angeles' => 'Kings', 'minnesota' => 'Wild', 'montreal' => 'Canadiens', 'nashville' => 'Predators', 'new_jersey' => 'Devils', 'ny_islanders' => 'Islanders', 'ny_rangers' => 'Rangers', 'ottawa' => 'Senators', 'philadelphia' => 'Flyers', 'phoenix' => 'Coyotes', 'pittsburgh' => 'Penguins', 'san_jose' => 'Sharks', 'st_louis' => 'Blues', 'tampa_bay' => 'Lightning', 'toronto' => 'Maple Leafs', 'vancouver' => 'Canucks', 'washington' => 'Capitals', ); %team_city = ( 'anaheim' => 'Anaheim', 'atlanta' => 'Atlanta', 'boston' => 'Boston', 'buffalo' => 'Buffalo', 'carolina' => 'Carolina', 'columbus' => 'Columbus', 'calgary' => 'Calgary', 'chicago' => 'Chicago', 'colorado' => 'Colorado', 'dallas' => 'Dallas', 'detroit' => 'Detroit', 'edmonton' => 'Edmonton', 'florida' => 'Florida', 'los_angeles' => 'Los Angeles', 'minnesota' => 'Minnesota', 'montreal' => 'Montreal', 'nashville' => 'Nashville', 'new_jersey' => 'New Jersey', 'ny_islanders' => 'New York', 'ny_rangers' => 'New York', 'ottawa' => 'Ottawa', 'philadelphia' => 'Philadelphia', 'phoenix' => 'Phoenix', 'pittsburgh' => 'Pittsburgh', 'san_jose' => 'San Jose', 'st_louis' => 'St. Louis', 'tampa_bay' => 'Tampa Bay', 'toronto' => 'Toronto', 'vancouver' => 'Vancouver', 'washington' => 'Washington', ); }