What it does: This script will poll COTI every 5 minutes, and display one-liner synopses of new entries. So you don't have to. Every 10 entries, it will print a divider line as a visual guide. It stores the state after a refresh, which it uses as a history to compare against in subsequent runs.
Synopsis: cotipoll.pl [polling interval [division interval]]
Defaults: Polling interval is 300 seconds. Division interval is 10 entries.
Requirements: Perl with LWP::Simple, Data:: Dumper, and of course an internet connection.
Synopsis: cotipoll.pl [polling interval [division interval]]
Defaults: Polling interval is 300 seconds. Division interval is 10 entries.
Requirements: Perl with LWP::Simple, Data:: Dumper, and of course an internet connection.
Code:
use LWP::Simple;
use Data::Dumper;
$Data::Dumper::Indent = 1;
$Data::Dumper::Terse = 1;
my $url = "http://www.travellerrpg.com/CotI/Discuss/index.php";
my $dbref = {};
$/ = undef;
open IN, '<', 'coti.dat';
$dbref = eval <IN>;
close IN;
my $wait = shift || 300;
print "Polling interval: $wait s\n";
my $interval = shift || 10;
print "Division interval: $interval\n";
my $intervaln = 0;
{
$dbref->{ 'timestamp' } = scalar localtime;
my @content = ();
my $html = get( $url );
for my $chunk (split /<a href="forumdisplay.php/, $html )
{
my $forum = $1 if $chunk =~ m|<strong>(.*?)</strong>|;
if ($forum)
{
my $topic = $1 if $chunk =~ m|Go to first unread post in thread (.*?)"|;
$topic =~ s|^.(.*).$|$1|;
my $time = $1 if $chunk =~ m|<span class="time">(.*?)</span>|;
next unless $time;
my $by = $1 if $chunk =~ m|find=lastposter.*?>(.*?)</a>|;
$forum = substr( $forum, 0, 20 );
$by = substr( $by, 0, 10 );
$topic = substr( $topic, 0, 44 );
my $key = sprintf "%-20s | %-10s | $topic", $forum, $by;
unless ( $dbref->{ $key } && $dbref->{ $key } eq $time )
{
$dbref->{ $key } = $time;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime;
my $now = sprintf "%02d/%02d %02d:%02d:%02d", $mon+1, $mday, $hour, $min+1, $sec+1;
push @content, "$now $key\n";
open OUT, '>', 'coti.dat';
print OUT Dumper( $dbref );
close OUT;
}
}
}
if ( @content )
{
print @content;
print '-' x 96, "\n" unless $intervaln % $interval;
$intervaln++;
}
sleep $wait;
redo;
}