#!/usr/bin/perl -w # # Takes three arguments and automatically creates an RSS feed for you. It should be added # to a cronjob, and run once daily (running multiple times a day will just give you the # same output, and burn extra cpu cycles. # # Arguments: # First is the text of the RSS. The text can be plain, or contain html markup if you want. # Each block of text should be followed by a single line containing . 'X' is the # day of the year that the preceding text should appear on. # # The Second argument is the file containing the 'channel' information. It should be in # proper RSS format, and need not contain the declaration, as the program will do # that for you. # # The third argument is the name of the file to output to, such as rss.xml # # All of these arguments are required, but this may change in the future to have decent # defaults. Full pathnames should be given, unless running directly from the command line. # # One variable in this line should be changed: $rssurl $rssurl = 'http://www.shanebishop.net/nau/rss.xml'; use DateTime; # grab the current date and initialize lots of variables for display in various places $date = DateTime->now; # if you want to test particular dates, modify the following line appropriately #$date = DateTime->new( year => 2008, month => 1, day => 5, hour => 2, minute => 12, second => 2); $doy = $date->day_of_year; $month_name = $date->month_name; $mday = $date->mday; $year = $date->year; $short_month = $date->month_abbr; $short_day = $date->day_abbr; $pubtime = $date->hms; # grab yesterdays date and initialize more variables prefixed with a 'y' $ydate = $date->subtract( days => 1 ); $yesterday = $ydate->day_of_year; $ymonth_name = $ydate->month_name; $ymday = $ydate->mday; $yyear = $ydate->year; $yshort_month = $ydate->month_abbr; $yshort_day = $ydate->day_abbr; # open a file to store the day of the year substituted on leapday # find out if it is a leap year, and if so, check to see if today is also leap day $leap = $date->is_leap_year; if ($leap and ($doy == 60)) { $doy = int(rand(364)) + 1; $leapday = 1; open LEAP, "> leap.day" or die $!; print LEAP $doy; } # if it is past leapday, we need to decrease the $doy and $yesterday values to keep on schedule if ($leap and ($doy > 61) and not $leapday) { $doy--; $yesterday--; } elsif ($leap and ($doy == 61) and not $leapday) { $doy--; open LEAP, "leap.day" or die $!; $yesterday = ; } # if it is the first day of the year after a leap year, we need to make a special condition to decrease $yesterday if (($ydate->is_leap_year) and ($doy == 1)) { $yesterday--; } open FEED, "> $ARGV[2]" or die $!; open CHANNEL, $ARGV[1] or die $!; open TEXT, $ARGV[0] or die $!; print FEED '' . "\n" . '' . "\n" . '' . "\n"; while () { print FEED $_; } print FEED '' . "$short_day, $mday $short_month $year 00:00:01 GMT" . '' . "\n" . '' . "$short_day, $mday $short_month $year $pubtime GMT" . ''. "\n" . 'http://blogs.law.harvard.edu/tech/rss' . "\n" . '' . "\n" . '' . "\n" . '' . "$month_name $mday" . '' . "\n" . '' . "$short_day, $mday $short_month $year $pubtime GMT" . '' . "\n" . '' . "$month_name $mday, $year" . '' . "\n" . '' . "\n"; if ($leapday) { print FEED '<p>Today is leap day (February 29). To make my life easier, I have opted not to create a completely separate set of readings for leap years. As a result, you have been given a random reading from a different day of the year. The normal schedule will resume tomorrow.</p>'; } if ($doy == 1) { $spit = 1; } $prior = $doy - 1; while () { if ($_ =~ //) { $spit = 0; } if ($spit) { print FEED $_; } if ($_ =~ //) { $spit = 1; } } close TEXT; open TEXT, $ARGV[0] or die $!; print FEED '' . "\n" . '' . "\n" . '' . "\n" . '' . "$ymonth_name $ymday" . '' . "\n" . '' . "$yshort_day, $ymday $yshort_month $yyear $pubtime GMT" . '' . "\n" . '' . "$ymonth_name $ymday, $yyear" . '' . "\n" . '' . "\n"; if ($leap and ($doy == 60) and not $leapday) { print FEED '<p>Today is leap day (February 29). To make my life easier, I have opted not to create a completely separate set of readings for leap years. As a result, you have been given a random reading from a different day of the year. The normal schedule will resume tomorrow.</p>'; } if ($yesterday == 1) { $spit = 1; } $prior = $yesterday - 1; while () { if ($_ =~ //) { $spit = 0; } if ($spit) { print FEED $_; } if ($_ =~ //) { $spit = 1; } } print FEED '' . "\n" . '' . "\n" . '' . "\n" . ''; close TEXT;