#!/usr/bin/perl # newentryatom.pl: for each line in diff output beginning with ">", create # a new atom entry announcing the creation of a new feed in rss directory. # If there are less then $entryCount entries, pad it with older entries # from $outFileName. # For demo purposes only. No warrantee expressed or implied. my $RSSDir = "/usr/www/users/bobd/rss/"; # This is actually used for input purposes, to get old entries for # padding if necessary. my $outFileName = $RSSDir . "newAtomFeeds.atom.bkp"; # Minimum number of entries to keep in feed file. my $entryCount = 8; # How many entries output so far. my $sourceItemCount = 0; # How many entries we'll need from the old file. my $oldEntriesToKeep = 0; my $URLStub = "http://www.snee.com/rss/"; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(); $year += 1900; my $dateTime = sprintf("%4d-%02d-%02dT%02d:%02d:%02dZ",$year,$mon,$mday,$hour,$min,$sec); print "\n"; print " $outFileName\n"; print " New Atom feeds in snee.com/rss\n"; print " $dateTime\n"; while (<>) { if (s/^>\s*//) { # If the diff output identified this as a new line chop($_); my $URL = $URLStub . $_ ; print " \n new Atom feed: $URL\n"; print " \n"; my $ID = $URL; $ID =~ s/\/rss\//\/id\//; print " $ID\n"; print " $dateTime\n"; print " \n"; $sourceItemCount++; } } # If we have output less than $oldEntriesToKeep entries, # get more from old file. $oldEntriesToKeep = $entryCount - $sourceItemCount; if ($oldEntriesToKeep > 0) { my $keep = 0; # Boolean my $retcode = open(INPUT, $outFileName); while() { $keep = 1 if ((/ 0)); print $_ if $keep; $oldEntriesToKeep-- if (/<\/entry>/); } close(INPUT); } print "\n";