#!/usr/bin/perl
use CGI qw/:all/;
use strict;
my $version = "0.2.7";
my $version_string = "Johnath's Toonsuck $version";
# Grab date info
my ($sec, $min, $hour, $mday, $month, $year, $wday, $yday, $isdst) =
localtime(time);
$month++; # starts from zero
$month = "0$month" unless length $month > 1;
$year += 1900;
$mday = "0$mday" unless length $mday > 1;
# Make sure we have a writeable temp dir
$ENV{TMPDIR} = '/tmp/';
# Now dump a page showing em all
print
header,
start_html(-BGCOLOR =>"#FFFFFF",
-title =>"toons.johnath.com",
-author =>"johnath\@johnath.com"),
h2("toons.johnath.com"),
p("Remember, a broken image may not actually be broken. The links for ".
"these images are auto-generated based on the date and what the ".
"particular site is expecting. If a cartoon has not, for example ".
"been posted yet today, the image will probably look broken."),
p("Also, some comics change between different graphics formats from time ".
"to time, possibly because of planetary alignments, possibly because ".
"it's just not their job to make my life easy. For those comics that ".
"do, I include an img tag for each standard format, which may result ".
"in some broken images even when the comic does show up."),
"\n";
# Now, if we just want today's comics, this next part is easy, but if we
# want backissues (if param('back')) then this needs to be a loop.
my $back_count = param('back') || 0;
for (my $n = 0; $n <= $back_count; $n++) {
print hr, h1("Back Issues from $n day(s) ago") if ($n >= 1);
# Generate URLs - this has to be done in here, so that they are updated
# properly when we decrement $mday. That is - if we specified these at the
# beginning of the program, as they seem to warrant, then this for loop
# would be useless, since changes to the effective date wouldn't DO
# anything.
# User-Friendly
my $uf_url = "http://ars.userfriendly.org/cartoons/?id=$year$month$mday";
my $uf_img;
my @uf_page = `lynx -source http://www.userfriendly.org/static/`;
my $uf_remainder = join / /, @uf_page;
$uf_remainder =~ /
/i;
$uf_img = "$1";
$uf_img =~ s/xuf/uf/i; # This gives us the big toon instead.
# PVP Online - Posted so late in the day that we grab yesterday's comic instead
my $pvp_url = "http://www.pvponline.com";
my $pvp_img;
#$pvp_img = "http://www.pvponline.com/archive/$year/pvp$year$month$mday.gif";
if($mday > 10) {
$pvp_img = "http://www.pvponline.com/archive/$year/pvp$year$month" . ($mday - 1) . ".gif";
} elsif ($mday > 1){
$pvp_img = "http://www.pvponline.com/archive/$year/pvp$year${month}0" . ($mday - 1) . ".gif";
} else {
$pvp_img = "http://www.pvponline.com/archive/$year/pvp$year$month$mday.gif";
}
# Sinfest
my $sin_url = "http://www.sinfest.net/";
my $sin_img = "http://www.sinfest.net/comics/sf$year$month$mday.gif";
# Penny-arcade
my $pen_url = "http://www.penny-arcade.com/";
my $pen_img = "http://www.penny-arcade.com/images/$year/$year$month${mday}l.gif";
my $pen_img_jpg = "http://www.penny-arcade.com/images/$year/$year$month${mday}l.jpg";
# Reallifecomics - notice the url doesn't use the date at all. RLC has
# moved to a rather annoying strip_id system - so we could either calculate
# it from a known-id, or we could just take advantage of the fact that if
# you over-shoot the current id, it just defaults to the most recent comic
my $rlc_url = "http://www.reallifecomics.com/";
my $rlc_img = "http://www.reallifecomics.com/daily.php?do_command=show_strip&strip_id=50000&auth=00000-00000-11111-00000-00000";
# Dilbert
my $dilbert_url = "http://www.dilbert.com/";
my $dilbert_img;
my $dilbert_page = join / /, `lynx -source http://www.dilbert.com/`;
$dilbert_page =~ /
$uf_url}, "User Friendly")),
a({href => $uf_url}, img({src=>$uf_img,border=>0})), "\n",
h2(a({href => $pvp_url}, "PVP Online")),
a({href => $pvp_url}, img({src=>$pvp_img,border=>0})), "\n",
h2(a({href => $sin_url}, "Sinfest")),
a({href => $sin_url}, img({src=>$sin_img,border=>0})), "\n",
h2(a({href => $pen_url}, "Penny Arcade")),
a({href => $pen_url}, img({src=>$pen_img,border=>0})), "\n",
a({href => $pen_url}, img({src=>$pen_img_jpg,border=>0})), "\n",
h2(a({href => $rlc_url}, "Real Life Comics")),
a({href => $rlc_url}, img({src=>$rlc_img,border=>0})), "\n",
h2(a({href => $dilbert_url}, "Dilbert")),
a({href => $dilbert_url}, img({src=>$dilbert_img,border=>0})), "\n",
h2(a({href => $pearls_url}, "Pearls Before Swine")),
a({href => $pearls_url}, img({src=>$pearls_img,border=>0})), "\n",
h2(a({href => $fuzzy_url}, "Get Fuzzy")),
a({href => $fuzzy_url}, img({src=>$fuzzy_img,border=>0})), "\n",
h2(a({href => $sp_url}, "Something Positive")),
a({href => $sp_url}, img({src=>$sp_img,border=>0})), "\n",
""; # ends this big print statement
# Decrement date counts - for gathering back issues.
$yday--;
$wday--;
$wday = 0 if ($wday < 0);
$mday--;
# Okay, updating mday when the month (and possibly year) just changed
# rots. Consider this a hacky enough solution. :) Some months won't have
# 31 days, but if you set back= high enough, you'll eventually get down
# to the useful ones.
if ($mday <= 0) {
$mday = 31;
$month--;
$month = "0$month" unless length $month > 1;
}
$mday = "0$mday" unless length $mday > 1;
}
print
center(hr), br, "\n",
center("This page generated by $version_string"),
"\n",
end_html;