Monday, April 27, 2009

Journal club cgi

For our journal club, I wrote a small cgi script that provides a web page where people can dump identifies of papers they are interested in and then everybody can see title, abstract and authours as well as a link to the pdf.

You can copy the file to your cgi-bin directory, make it world executable and create a world writeable directory /opt/journal . You might need to install the XML::TreeBuilder module (as root run 'perl -MCPAN -e shell' and then do 'install XML::TreeBuilder'.

# Journal club cgi
# Written by Robert C. Helling (
# Published under the Gnu Public License (most recent version)

use XML::TreeBuilder;
use LWP::Simple;
use CGI;

my $g = CGI::new();
print "Content-type: text/html\n\n";
my @ids = ();

system "touch /opt/journal/numbers";
open (IN,'/opt/journal/numbers') ||die "Cannot open /opt/journal/numbers:$!!";;
push @ids, $1;
@ids = ();
close IN;

if($new_paper = $g->param('paper_id')){
my ($new_id) = $new_paper =~ /(\d\d\d\d\.\d\d\d\d)/;
push @ids,$new_id;
open (OUT, ">>/opt/journal/numbers") || die "Cannot write to /opt/journal/numbers:$!";
print OUT "$new_id\n";
print "\nNEW$new_id\n";
close OUT;

my %seen = ();
@ids = grep { ! $seen{$_} ++ } @ids;

dbmopen %papers, '/opt/journal/papers', 0666;

print join '
<hr>', map {&show($_)} @ids;

print ($g->start_form(),
$g->submit(-name => "add paper"),

sub show{
my $id = shift;
my $data;

unless($data = $papers{$id}){
$data = get("\&$id\&metadataPrefix=arXivRaw");
$papers{$id} = $data;

my $all = XML::TreeBuilder->new;

my $authors = $all->find('authors')->as_text;
my $title = $all->find('title')->as_text;
my $abstract = $all->find('abstract')->as_text;

return "$authors\n<a href=\"$id\">$title</a>\n$abstract\n";

dbmclose %papers;