#!/usr/pkg/bin/perl -w use strict; use LWP::Simple; use Time::Local; use CGI; my $query = new CGI; my $m=$query->param('m'); my $d=$query->param('d'); my $y=$query->param('y'); my $days = $query->param('days'); my $time = timelocal(0,0,0,$d,$m,$y); my $thistime = 0; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = (0,0,0,0,0,0,0,0,0); my $offset = 0; my $date = 0; my $sdate = "2006/01/01"; print "Content-type: text/csv\n\n\n"; print "Date,VISITOR,Q1,Q2,Q3,Q4,OT,MIN,FG,FG ATT,FT,FTA,OFF REB,DEF REB,REB,AST,PF,ST,TO,PTS,3PT,3PT ATT,HOME,Q1,Q2,Q3,Q4,OT,MIN,FG,FG ATT,FT,FTA,OFF REB,DEF REB,REB,AST,PF,ST,TO,PTS,3PT,3PT ATT\n"; for (my $i=0;$i<$days;$i++) { $thistime = $time - ($i*86400); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($thistime); $mon++; $year+=1900; if ($mon<10) { $date = $year.'0'.$mon; $sdate = $year.'/0'.$mon; } else { $date = $year.$mon; $sdate = $year.'/'.$mon; } if ($mday<10) { $date = $date."0".$mday; $sdate = $sdate.'/0'.$mday; } else { $date = $date.$mday; $sdate = $sdate.'/'.$mday; } my $output = ''; my $topteam = ''; my $bottomteam = ''; my $waste = ''; my $tpm1 = ''; my $tpm2 = ''; my $tpa1 = ''; my $tpa2 = ''; my $tpcount = 'false'; my $foundscore = 'false'; my $lineinfo = ''; my $scores = ''; my $visitorscore = ''; my $homescore = ''; my @hsp = (1,2); my @vsp = (1,2); my $vots = 0; my $hots = 0; my $thisvots = 0; my $thishots = 0; my $donbesturl = "http://www.donbest.com/website/html/scores/L3.shtml?$date"; my $html = get($donbesturl); my @htmlparts = split('', $html); @htmlparts = split('', $htmlparts[3]); my @games = split('\n', $htmlparts[0]); my $games = @games; for (my $i=1;$i<$games;$i++) { my @parts = split("/",$games[$i]); my @gameparts = split('.js',$parts[3]); my $game = $gameparts[0]; my $recap = "http://donbest.com/scores/$date/$game.js"; my $recaphtml = get($recap); my @recapparts = split('\n',$recaphtml); my $recaplen=@recapparts; my $ot = $recaplen-34; $vots = 0; $hots = 0; if ($ot>0) { $ot = $ot/2; for (my $count=0;$count<$ot;$count++) { $_ = $recapparts[$count+10]; (my $thisvots) = m/.*>(.*)<.*/g; $vots += $thisvots; $_ = $recapparts[$ot+$count+27]; (my $thishots) = m/.*>(.*)<.*/g; $hots += $thishots; #10,11,29,30 } }else { $vots=''; $hots=''; }; my $x=12; my $y=29; $_ = $recapparts[$x+$ot]; (my $over) = m/.*>(.*)<.*/g; $ot*=2; $_ = $recapparts[$y+$ot]; (my $line) = m/.*>(.*)<.*/g; $lineinfo = "$over,$line"; my $boxscore = "http://donbest.com/boxscores/$date/$game.htm"; my $boxscorehtml = get($boxscore); my @boxscorelines = split('\n',$boxscorehtml); my $csv = ''; for (@boxscorelines) { if (m/ AT /g) { my @teamparts = split(' AT '); my $top = $teamparts[0]; my @topparts = split('\(',$top); $topteam = $topparts[0]; $visitorscore = $topteam; my $bottom = $teamparts[1]; my @bottomparts = split('\(',$bottom); $bottomteam = $bottomparts[0]; $homescore = $bottomteam; } if (m/TOTALS.*/g) { $csv .= $_; } if (m/3-PT. FIELD GOALS: /g) { $line = $_; my @tptpartstop = split($topteam,$line); (my $tptparts1, $waste) = split('\(',$tptpartstop[1]); ($tpm1, $tpa1) = split('-', $tptparts1); my @tptpartsbot = split($bottomteam,$line); if (!$tptpartsbot[1]) { $tpcount='true'; } else { $_ = $tptpartsbot[1]; s/\r//g; (my $tptparts2, $waste) = split('\('); ($tpm2, $tpa2) = split('-', $tptparts2); } } if ($tpcount eq 'true') { my @tptpartsbot = split($bottomteam); if ($tptpartsbot[1]) { (my $tptparts2, $waste) = split('\(',$tptpartsbot[1]); ($tpm2, $tpa2) = split('-', $tptparts2); $tpcount='false'; } else { $tpcount='true'; } } if ($foundscore eq 'true') { my @homescoreparts = split('-'); @homescoreparts = split($bottomteam,$homescoreparts[0]); $homescore = $homescoreparts[1]; @hsp = split(/\s+/,$homescore); $foundscore = 'false'; } if (m/^\s*($topteam)\s*[0-9\s]*/) { my @visitorscoreparts = split('-'); @visitorscoreparts = split($topteam,$visitorscoreparts[0]); $visitorscore = $visitorscoreparts[1]; @vsp = split(/\s+/,$visitorscore); $foundscore = 'true'; } } $_ = $csv; s/\r//g; s/^\s//g; s/REBOUNDS//g; s/[\s]+/,/g; s/-/,/g; my @csvparts = split('TOTALS'); $_ = "$sdate,$topteam,$vsp[1],$vsp[2],$vsp[3],$vsp[4],$vots".$csvparts[1].",$tpm1,$tpa1,"."$bottomteam,$hsp[1],$hsp[2],$hsp[3],$hsp[4],$hots".$csvparts[2].",$tpm2,$tpa2,".$lineinfo."\n"; s/\r//g; print; } }