#!/usr/bin/perl # Display a wbc index of games # Bruno Wolff III # Last revised October 13, 2012 # Use unbuffered output as there are some long delays while doing queries select(STDOUT); $| = 1; $" = ''; use Pg; # Use this to clean stuff extracted from the database for html output sub clean(@) { local $str = "@_"; $str =~ s/&/&/g; $str =~ s//>/g; $str =~ s/"/"/g; return $str; } if ($ENV{REQUEST_METHOD} ne '' && $ENV{REQUEST_METHOD} ne 'GET' && $ENV{REQUEST_METHOD} ne 'HEAD') { print <<"EOF"; content-type: text/html; charset=UTF-8 status: 501 Method not implemented 501 Method Not Implemented

Method Not Implemented

Method '$ENV{REQUEST_METHOD}' not implented for $ENV{REQUEST_URI}. EOF exit; } print < AREA WBC Code Index

AREA WBC Code Index

EOF # First try to connect $conn = Pg::connectdb('dbname=area'); if ($conn->status != PGRES_CONNECTION_OK) { print << "EOF"; Unable to connect the AREA database. EOF exit; } # Only one query is done so we don't need to set transaction isolation. $result = $conn->exec("select code, event, url, wbcgames.gameid, title from wbc natural left join (wbcgames natural join games) order by code, lower(title), gameid"); if ($result->resultStatus != PGRES_TUPLES_OK) { print << "EOF"; Unable to access the games or wbc tables. EOF exit; } if ($result->ntuples <= 0) { print << "EOF"; No games were found. EOF exit; } print "\n\n"; while (@row = $result->fetchrow) { $code = clean($row[0]); $event = clean($row[1]); $url = clean($row[2]); $game = clean($row[3]); $title = clean($row[4]); if (defined($row[2])) { print "
WBC codeWBC EventGame Title
$code$event"; } else { print "
$code$event"; } if (defined($row[3])) { print "$title"; } print "\n"; } print << "EOF";
EOF