#!/usr/bin/perl
# Time-stamp: "2024-11-14 05:15:26 MST"
#
# See http://www.interglacial.com/rss/ for info on RSS feeds
#

require 5;
use strict;
use constant DEBUG => $ENV{'MAILTO'} ? 0 : 2;
use XML::RSS::SimpleGen 12;

my $dir =
 ( $ENV{'HOME'} || die "No home?" ) . "/interglacial/jerkcity_jumble"
;

opendir DIR, $dir or die "Can't read-open $dir: $!";
my( @them ) = sort grep m/^jerk_.+\.html/, readdir(DIR);
closedir(DIR);
die "Not enough input files!" unless @them >= 366;
my $day =  (localtime)[7];
my $today = $them[$day];
DEBUG and print "Input file for d$day: $today\n";

open(IN, "$dir/$today") or die "Can't read-open $dir/$today: $!";
my $jumble;
{
  local $/;
  $_ = <IN>;
  close(IN);
  if( m{class='problem'>(.*?)</} ) {
    $jumble = $1;
    DEBUG and print "  Jumble: $jumble\n";
  } else {
    DEBUG and print "  No jumble in $dir/$today ?!\n";
  }
}


my $nombre = 'jerkcity_jumble';
rss_new(
  "http://interglacial.com/rss/$nombre.rss",
  "The Daily Jerkcity Jumble",
);
rss_self_url(      "http://interglacial.com/rss/$nombre.rss" );
rss_generator_url( "http://interglacial.com/rss/$nombre.pl"  );
rss_daily;
rss_language("en-US");
rss_webmaster('sburke@pobox.com');
rss_item( "http://interglacial.com/jerkcity_jumble/$today", $jumble || $today );
rss_livejournal( 'jerkjumble' );
rss_save( "$nombre.rss", 30 );
exit;

__END__
