#!/usr/local/bin/perl # gkrellscore.excite # # based on the script included with wmScoreBoard by Todd Kuper- # quite an excellent piece of work, if I may say so.. There are some # other lookalikes floating around, but I am pretty sure he wrote # the original. # # Distributed under the terms of the GNU Public License # # paul cannon #--------------------------------------------------------------------- # # This script downloads the appropriate web page from Excite and # parses the current (or final) score from the game the specified # team (for the specified sport) is playing in. # # Modify this script as needed if you prefer another web site. # Feel free to email your scripts to me. # #--------------------------------------------------------------------- # Get the Excite sport code from the command line # Examples: nba for men's professional basketball # ncaab for men's college hoops $sport = shift; # Get the Excite team code from the command line # Examples: col for the Colorado Avalanche # iao for the Iowa State Cyclones $team = shift; # Excite's scoreboard web page $url = "http://sports.excite.com/"; # This page has all the scores $workurl = $url . $sport; $workurl .= '/scoreboard' if ( $sport eq 'ncaab' ); # Setup the filenames $home = (getpwuid ($<))[7]; $dir = "$home/.gkrellm/data/gkrellscore"; $sport_file = "$dir/scores.$sport.$team"; $errormsg = "No score\n\navailable.\n\n\n\n\n\n"; # The download command. You could use the commands from Lwp and HTTP # Perl modules instead $wget_command = 'wget'; $wget_options = "-q --cache=off -O $sport_file"; # Prepare the place where we'll put the HTML files mkdir $dir,0755; system "$wget_command $wget_options $workurl"; # Excite's scores are in an HTML table so look for row markers $/ = ''; open (HTML, "<$sport_file") or exit 1; LINE: while () { # Look for the date of the game if (/SCORES\s*( )?\s*([\w\s]+)\s*\/gi; # Mangle this row until it gets into a somewhat readable form s/\n//g; # get rid of newlines s/ / /g; #   should be real space s/<.*?>/#/g; # remove HTML tags s/#\s+#/#/g; # remove useless white space s/^[\s\d\#]*//; # get rid of rankings s/\#+/#/g; # get rid of consecutive #'s s/#\s+(\S)/\#$1/g; # get rid of whitespace at beginning s/(\S)\s+#/$1#/g; # get rid of whitespace at end s/\s+/ /g; # get rid of consecutive whitespace s/#\s*\-\d+\.5\s*#/# # #/; # get rid of odds s/# *TV\:.*? *#/#/; # get rid of tv station # Finally, we can parse the info we need ($visitors, $at, $home, $visitors_score, $home_score, $time, $period) = split ("#", $_); $period = $time . " " . $period; $period =~ s/^ ?F/Final/; # Get rid of periods $visitors =~ s/\.//g; $home =~ s/\.//g; # Get rid of leading ' ' $visitors_score =~ s/^ +$//; $home_score =~ s/^ +$//; # Check for error conditions if ($home_score =~ /\:/) { $period = $home_score; $home_score = ''; $visitors_score = ''; } if ($visitors_score =~ /\:/) { $period = $visitors_score; $home_score = ''; $visitors_score = ''; } if ($home !~ /^[A-Za-z ]+$/ || $visitors !~ /^[A-Za-z ]+$/) { print $errormsg; exit; } # Check if the user's team is playing at home or away $role = "?"; $homecode = ($homeurl =~ /^\/*$sport\/(.*?)\/*$/) ? $1 : "H"; $viscode = ($visurl =~ /^\/*$sport\/(.*?)\/*$/) ? $1 : "V"; ($homecode eq $team) && ($role = "H"); ($viscode eq $team) && ($role = "V"); # Print the info to the scores file in the form GKrellKam is expecting print "$home ($homecode)\n"; print "$home_score\n"; print "$visitors ($viscode)\n"; print "$visitors_score\n"; print "$period\n"; print "$date\n"; print "$role\n"; $gameurl =~ s/^\/*//; print ($url . $gameurl . "\n"); exit 0; } } print "$errormsg"; exit 0;