http://www.perlmonks.org?node_id=74141


in reply to RE: seeker watch
in thread seeker watch

I updated the script to work with unapproved questions. I don't like to be popped, so it dumps on term only. I shamelessly copied the passwd stuff from jcwren's luke_repwalker.
#!/usr/bin/perl -w use strict; use LWP::Simple; use Getopt::Std; use URI::Escape; use constant APPROV => 'Approved'; use constant UNAPPROV => 'Unapproved'; my $poll = 60; my %question = ( APPROV, '', UNAPPROV,''); my $count = 0; $|=1; { my %args; getopts('u:p:', \%args); # Replace these dies with username/password my $user = $args{u} || 'jeroenes' || # You can put your name here die("You need to specify the user with -u"); my $pass = $args{p} || 'youdontwannaknowdoyou' || # You can put yo +ur password here die("You need to specify the password with -p"); main( $user, $pass ) while (1); } sub main { watch( @_); my @secs = times; $secs[0] += $secs[2]; $secs[1] += $secs[3]; printf "Done %5i fetch%s since last new question. CPU: %8.3f user; + %8.3f system\r", ++$count, $count>1?'es':'', @secs; sleep $poll; } sub watch { my $url = 'http://perlmonks.org/index.pl?node=Seekers%20of%20Perl% +20Wisdom'; if (@_) { my $user = uri_escape(shift); my $passwd = uri_escape(shift); $url .= "&op=login&user=$user&passwd=$passwd"; } my $content = get($url) or return; if ($content =~ m/<font color=white>User Questions<\/font>.+?<a hr +ef=\"\/index\.pl\?node_id=\S+\">(.*?)<\/a>/is) { compare( APPROV, $1); } if ($content =~ m/<font color=white>Unapproved Questions<\/font>.+ +?<a href=\"\/index\.pl\?node_id=\S+\">(.*?)<\/a>/is) { compare( UNAPPROV, $1); } } sub compare { my $state = shift; my $curquestion = shift; if ($question{$state} ne $curquestion) { $question{$state} = $curquestion; act($state); $count = 0; } } sub act { my $state = shift; print "\nNew $state PerlMonks Question: $question{$state}\n"; }
prints out some CPU info while waiting....

cheers,

Jeroen
"We are not alone"(FZ)