#!/usr/bin/perl -w use strict; $|++; use LWP::Simple qw(mirror); use CGI qw(:all -no_debug col thead tbody); use HTML_TAGS; use Getopt::Long; my $CNN_URL = "http://headlinenews.cnn.com/QUICKNEWS/virtual/swf.headline.txt"; my $CNN_CACHE = "contest.cnn-cache"; # flat file my $DB_MEMORY = "contest.memory"; # dbmopen { my $s = mirror($CNN_URL, $CNN_CACHE); last if $s == 200; # we got new data last if $s == 304; # no new data, but we have to expire things die "status is $s, aborting\n"; } GetOptions( "refresh=i" => \ (my $REFRESH = 10), # meta refresh time in minutes "output=s" => \ (my $OUTPUT = "/usr/local/apache/htdocs/headlines.html"), # output file "expire=i"=> \(my$EXPIRE= 15), # expire time in minutes (Originally 1440) "clear!" => \ (my $CLEAR = 0), # clear the cache "<>" => sub { $Getopt::Long::error++; warn "Unknown arg: $_[0]\n" }, ) or die "see code for usage\n"; dbmopen(my %DB, $DB_MEMORY, 0644) or die "Cannot dbmopen $DB_MEMORY: $!"; open STDIN, $CNN_CACHE or die "Cannot open $CNN_CACHE: $!"; open STDOUT, ">$OUTPUT" or die "Cannot create $OUTPUT~: $!"; %DB=()if $CLEAR; $CGI::Q = CGI->new(\*STDIN) or die "Cannot parse $CNN_CACHE\n"; for (my $i = 1; my $headline = param("headline$i"); $i++) { my $state = param("state$i"); my $key = "$state\n$headline"; if (defined $DB{$key}) { # just update modtime $DB{$key} =~ s/\s\d+/" " . time/e; } else { # add the entry $DB{$key} = time . " " . time; } } for my $key (keys %DB) { delete $DB{$key} if $DB{$key} =~/\s(\d+)/ and $1 < time - $EXPIRE * 60; } print start_html(-title => "Thunderheart -- Brought to you in Ronovision!", head => meta({-http_equiv => 'refresh', -content => $REFRESH*60})); print <<'HTML';
| Thunderheart |
|---|