#!/usr/bin/perl # footie-alert v0.1 - send sms alerts when football team are playing # (c) April 2002 - James Powell - http://www.webscalability.com/ # usage ./footie-alert.pl [team] # requires a config file in $HOME/.footie-alert of format # username=fred # password=toot # mobilenum=0797777666 use Net::SMS::Genie; use LWP::Simple; use HTML::Parser; use Data::Dumper; use strict; # load in genie username & pw & mobile # to alert # {{{ open (CONF, "$ENV{HOME}/.footie-alert") or die $!; my %conf; while () { next if /^#/; s/\s+//; my($key,$val) = split /=/; next unless (defined($key) && defined($val)); $conf{$key} = $val; } close(CONF); # }}} my $scorepage = get('http://www.livescore.co.uk/default.dll?England') or die $!; # print $scorepage; my $inbold = undef; my @alltext; my $score = undef; my @scorestore; my $team = $ARGV[0]; $team ||= 'tottenham'; &get_score; # {{{ starttag sub starttag { my($tagname, $attr) = @_; if ($tagname eq 'n') { $inbold = 1; } } # }}} # {{{ endtag sub endtag { my($tagname) = @_; if ($tagname eq 'n') { $inbold = undef; } } # }}} # {{{ text sub text { my($text) = @_; push @alltext, $text; # print $text; if ($text =~ /$team/i) { if ($alltext[$#alltext - 1] =~ /\d+ - \d+/) { # last entry is a score, playing away @scorestore = @alltext[($#alltext - 2)..$#alltext]; } else { # playing at home - need to get 2 more push @scorestore, $text; } } elsif ($#scorestore > -1) { # playing get home - get those 2 more push @scorestore, $text; } if ($#scorestore == 2) { # score array is complete $score = join " ", @scorestore; } } # }}} # {{{ get_score sub get_score { my $p = HTML::Parser->new( api_version => 3, start_h => [\&starttag, "tagname, attr"], end_h => [\&endtag, "tagname"], text_h => [\&text, "dtext"], marked_sections => 1 ); $p->parse($scorepage); if ($score) { &send_score($score); } else { die "No score retrieved"; } } # }}} # {{{ send_score sub send_score { my $locscore = shift; my $sms = Net::SMS::Genie->new( autotruncate => 1, username => $conf{username}, password => $conf{password}, recipient => $conf{mobilenum}, subject => 'SCORE', message => $locscore, ); #$sms->verbose( 1 ); $sms->send_sms(); # my $quota = $sms->quota(); } # }}} exit 0;