#!/usr/athena/bin/perl

#
# temp-shuttletrack.pl
#
# This script is a temporary measure around the fact that wget 
# in the gnus locker is outdated, which is a temporary measure 
# around the fact that wget is not installed locally, which will 
# be solved when we upgrade from Athena 9.3 to Athena 9.4, which 
# will happen when we upgrade our hardware.
#
# Would you like a yak with the preceding sentence?
#
# This script fingers saferide@character.mit.edu

# Get the finger output
my @answer = `finger saferide\@character.mit.edu`;

# Get rid of the "finger puppet" explanation
shift(@answer);
shift(@answer);
shift(@answer);
shift(@answer);

# Open temporary file
open(SAFERIDE, '> /var/www/processed/shuttletrack-tmp.html');
#print SAFERIDE "Route | Time | Current stop | Next stop<br>";

# Write to file
for ($i=0; $i<=$#answer; $i++) {  # Iterate over the array
  print SAFERIDE "&nbsp;&nbsp;&nbsp;";	# tab in all saferide stuff
  my $orig= $answer[$i];		# grab the line corresponding with the route 
    $orig =~ /(\d\d:\d\d:\d\d)/;        # and make it look pretty
    my $time = $1;
    my @info = split /\d\d:\d\d:\d\d/, $orig;	# split route and stops info
  print SAFERIDE "$info[0] | $time | $info[1]";
  print SAFERIDE "<br>";		# don't forget the newline
}

# Close file and exit
close(SAFERIDE) || die;

# Replace temporary file
`mv /var/www/processed/shuttletrack-tmp.html /var/www/processed/shuttletrack.html`;
