use LWP::UserAgent;
use HTML::TableParser;
use XML::RSS;
####
use strict;
use warnings;
use LWP::UserAgent;
use HTML::TableParser;
use XML::RSS;
use constant ENTRANTS_PAGE =>
'http://www.example.com/lotteryentr?eventid=1221';
use constant RSS_FILE =>
'/var/www/html/lottery_entrants.xml';
my $response = LWP::UserAgent->new()->get(ENTRANTS_PAGE);
die $response->status_line()
unless ($response->is_success());
my ($paid, $not_paid) = (0, 0);
my $p = HTML::TableParser->new([
{
cols => 'Paid',
row => sub {
$_[2]->[3] eq 'Paid' and $paid++
or $_[2]->[3] eq 'Not Paid' and $not_paid++;
}
}], { Decode => 1, Trim => 1, Chomp => 1 });
$p->parse($response->content());
my $now = localtime;
my $rss;
if (-s RSS_FILE){
$rss = XML::RSS->new();
$rss->parsefile(RSS_FILE);
}
else{
$rss = XML::RSS->new( version => '2.0' );
$rss->channel(
title => 'Lottery Entrants',
pubDate => $now,
syn => {
updatePeriod => "hourly",
updateFrequency => "3",
updateBase => "1901-01-01T00:00+00:00",
});
}
$rss->add_item(
title => "Entrants at $now",
description => "$paid have paid, $not_paid haven't");
$rss->save(RSS_FILE);