App-arxiv2bib
view release on metacpan or search on metacpan
script/arxiv2bib view on Meta::CPAN
($help) && do {
pod2usage(-verbose => 1);
exit;
};
($man) && do {
pod2usage(-verbose => 2);
exit;
};
sub entry2hsh($entry) {
my %h;
for (qw(id updated published title summary)) {
$h{$_} = $entry->at($_)->text;
}
$h{'authors'} = $entry->find('author name')->map('text');
$h{'category'} = $entry->find('category')->map(sub {$_->{'term'}});
$h{'abs'} = $entry->at('link[type="text/html"]')->{'href'};
$h{'pdf'} = $entry->at('link[type="application/pdf"]')->{'href'};
return \%h;
}
sub hsh2strings($h,$label) {
my $authors = $h->{'authors'}->join(', ');
my $title = $h->{'title'};
my $year = ($h->{'published'} =~ /^(\d*)/) && $1;
my $id = $h->{'id'};
$label//= ($id =~ /.*\/(.*)/) && $1;
return [$label,$authors,$title,$year,$id];
}
sub hsh2bbtx($h,$label) {
my ($l,$authors,$title,$year,$id) = @{hsh2strings($h,$label)};
my $msg = << "EOF";
\@misc{$l,
Author = {$authors},
Title = {$title},
Year = {$year},
note = {$id},
}
EOF
return $msg;
}
sub hsh2ams($h,$label) {
my ($l,$authors,$title,$year,$id) = @{hsh2strings($h,$label)};
my $msg = << "EOF";
\\bib{$l}{misc}{
author={$authors},
title={$title},
date={$year},
note={$id},
}
EOF
return $msg;
}
sub renderEntry($entry,$label,$type) {
(exists $type->{raw}) && return Dumper(entry2hsh($entry));
(exists $type->{amsrefs}) && return hsh2ams(entry2hsh($entry),$label);
return hsh2bbtx(entry2hsh($entry),$label);
}
my $ua = Mojo::UserAgent->new;
$ua = $ua->max_redirects(3);
my $baseURL="http://export.arxiv.org/api/query";
my %form=(
( run in 0.701 second using v1.01-cache-2.11-cpan-65fba6d93b7 )