#!/usr/bin/perl
#
# Get all team stats from 1995 - present in AL
#

$debug = 1;

$start_year = 1995;
$end_year = 2006;
@team_list = ("BAL", "BOS", "NYY", "TBD", "TOR",
              "MIN", "DET", "CHW", "CLE", "KCR",
              "OAK", "LAA", "TEX", "SEA" );

for ($year = $start_year; $year <= $end_year; $year++) {


  foreach $team (@team_list) {

   $new_team = $team;

   if (($team eq "LAA") && (($year < 2005) && ($year >= 1997))) {
     $new_team = "ANA";
   }
   if (($team eq "LAA") && (($year < 1997) && ($year >= 1995))) {
     $new_team = "CAL";
   }
   if (($team eq "TBD") && ($year < 1998)) {
     next;
   }


   $outfile = sprintf "./team_stats/%s_%04d.html", $new_team, $year;

   $cmd = "curl ";
   $cmd .= " -o $outfile ";
   $cmd .= sprintf "%s/%s/%04d.shtml", 
      "http://www.baseball-reference.com/teams", $new_team, $year;
   if ($debug > 0) {
     printf "cmd is ..$cmd.. \n", $cmd;
   }
   $ret = `$cmd`;

  }

}

exit 0;
