#!/usr/bin/perl
#
#Dada Pokey list generator
#v2.0
#by Leonard Richardson leonardr@segfault.org
#
#This handles both Daily Pokey and Best of Dada Pokey.
@months = qw/TILT! January February March April May June July August September October November December/;
$data_path = "/home/leonardr/public_html/features/dada/pokey/data/";
$best_list = $data_path . "best.txt";
$daily_list = $data_path . "daily.txt";
$list_url = "list.cgi";
#Take care of being called from an SSI cmd directive.
$mode = $ARGV[0];
$cgi = ($mode eq "");
if (!$cgi)
{
if ($mode eq "daily")
{
$granularity = "top";
}
} else {
use CGI qw(:standard);
print header;
$mode = param("mode");
$viewer_url = "pokey.cgi?mode=$mode&id=";
}
if ($mode eq "best")
{
$viewer_url = "pokey.cgi?mode=view&id=";
make_best_list();
} else {
if ($cgi)
{
$year = param("year");
$position = param("position");
$granularity = param("granularity") or $granularity = "top";
}
make_daily_list($granularity,$year,$position);
}
###############################################################################
sub make_best_list
{
#The input file is in the format query_string:title:discoverer,
#last 2 can be left blank.
open LIST, $best_list or die "CAN'T FIND $best_list!! TRULY A SETBACK OLD BEAN!!!";
print "
\n";
while ()
{
chomp();
($data,$desc,$discover) = split /:/;
print "- ";
if (!($desc)) { print "NO TITLE GIVEN"; } else { print $desc; }
print "";
if ($discover) { print " (found by $discover)"; }
print "
\n";
}
print "
\n";
}
###############################################################################
sub make_daily_list
{
($granularity,$year,$position) = @_;
@valid_granularities = ("top","year","month");
#Grab the entries and put them in a hash.
open (BEST, $daily_list);
while ()
{
chomp();
($date,$strip) = split /:/;
$date =~ /^(\d+)(\d{2})(\d{2})$/;
$syear = $1; $smonth = $2; $date = $3;
$strips{$syear}{$smonth}{$date} = $strip;
}
if ($granularity eq "top")
{
list_years();
} elsif ($granularity eq "year") {
list_months($year);
} elsif ($granularity eq "month") {
list_strips_for_month($year,$position);
}
}
sub list_years()
{
print "";
}
sub list_months
{
($year) = @_;
print "Daily Pokey archives for $year
\n";
print "";
}
sub list_strips_for_month
{
($year, $month) = @_;
print "Daily Pokey archives for $months[$month], $year
\n";
print "";
}
#This sub is just for testing purposes. It makes sure that the data
#was read correctly from the file.
sub print_entries
{
foreach $year (sort keys %strips)
{
print "Strips for year $year:\n";
foreach $month (sort keys %{$strips{$year}})
{
print " Strips for $year/$month:\n";
foreach $day (sort keys %{$strips{$year}{$month}})
{
print " $year/$month/$day: $strips{$year}{$month}{$day}\n";
}
}
}
}