#!/usr/bin/perl
#DADA POKEY!!
#v2.0
#
#Written by Leonard Richardson leonardr@segfault.org
#Pokey brings out the fun in music!
#
#Please give me credit if you use the Dada Pokey code or idea, or Pokey will
#be angry with you. Thank you.
#The new version 2.0 brings together scattered Pokey functionality
#into two programs; a viewer and a lister. The viewer views (Dada,
#Best of, and Daily), the lister lists (Best Of and Daily). End of
#story.
use POSIX qw(strftime);
#$mirror_url = "http://mrnutty.zabbo.net/pokey/archive/";
$mirror_url = "http://www.yellow5.com/pokey/archive/";
$pokey_dir = "http://" . $ENV{'SERVER_NAME'} . "/features/dada/pokey/";
$dada_image_url = $pokey_dir . "dadapokey.gif";
$daily_image_url = $pokey_dir . "dailypokey.gif";
$image_url = $dada_image_url;
$cgi_url = $pokey_dir . "pokey.cgi";
$title = "
DADA POKEY!!
";
$arg = @ARGV[0];
$online = ($arg ne "daily");
$pokey_path = "/home/leonardr/public_html/features/dada/pokey/data/";
if ($online)
{
use CGI qw(:standard);
$mode = param("mode") or $mode = "view";
if ($mode eq "daily")
{
$image_url = $daily_image_url;
$mode = "view";
}
$id = param("id");
print "Content-Type: text/html\n\n";
} else {
$mode = "dada";
$pokey_path = '/home/leonardr/public_html/features/dada/pokey/data/';
}
$count_path = $pokey_path."counts.txt";
$daily_path = $pokey_path."daily.txt";
if ($mode eq "dada")
{
dada($online);
} elsif ($mode eq "view") {
view($id);
} else {
dada($online);
}
##########################################################################
sub dada
{
my ($online) = @_;
#Input the counts and get a running total.
open COUNT, $count_path or die "COUNT PATH $count_path NOT AVALIABLE! WHAT A PITY!!! $!";
while()
{
$total_panels += $_;
push @panel_numbers, $_;
}
#Get the number of panels, not counting the obligatory title
#panel, for the generated comic. What we'll do is pick a comic at
#random and use that comic's length. This will give us a realistic
#distribution of comics.
$panels_for_this_comic = @panel_numbers[rand(scalar(@panel_numbers))];
#Generate each dada panel in turn.
for ($panel_counter = 1;
$panel_counter <= $panels_for_this_comic;
$panel_counter++)
{
#We want each panel to be equally likely. So we pick a number
#between 1 and $total_panels and iterate through the comics
#until we find the associated panel.
$target_panel = int(rand $total_panels) + 1;
$panel_location_within_comic = $target_panel;
$comic_number = 0;
$panel_number = 0;
#Find the right comic and the right panel in that comic.
while ($panel_number + @panel_numbers[$comic_number] < $target_panel)
{
$panel_number += @panel_numbers[$comic_number];
$panel_location_within_comic -= @panel_numbers[$comic_number];
$comic_number++;
}
$comic_number++;
push @comics, $comic_number . "_" . $panel_location_within_comic;
}
if ($online)
{
print_comic_page(@comics);
} else {
`touch $daily_path` unless (-e $daily_path);
$date = strftime "%Y%m%d", localtime(time());
$current_daily = `cat $daily_path`;
$new_daily = "$date:".join("!",@comics)."\n" . $current_daily;
open(DAILY, "> $daily_path");
print DAILY $new_daily;
close DAILY;
}
}
##########################################################################
sub view
{
my ($id) = @_;
#By default, gets today's Daily Pokey.
if ($id eq "")
{
open(DAILY, $daily_path);
$input = ;
($date, $id) = split /:/, $input;
$image_url = $daily_image_url;
$title = "";
}
@data = split /!/, $id;
while(@data)
{
$_ = shift @data;
push @comics, $_;
}
print_comic_page(@comics);
}
##########################################################################
sub print_comic_page
{
(@comics) = @_;
print <
DADA POKEY CANNOT HELP BUT ROCK THE HOUSE, OLD BEAN!
$title

END
foreach $comic (@comics)
{
print "
\n";
#Build a URL so that this comic can be bookmarked or used in BODP.
$best_url .= $comic."!";
}
chop($best_url);
$best_url .=
print <HELLO . POKEY THE PENGUIN LOVE
S TO READ YOUR EMAIL AND SO
DOES LEONARDR.
DID YOU LIKE THIS COMIC? IT
LIVES HERE
POKEY THE PENGUIN IS COPYRIGHT © 1998-2002
THE AUTHORS