Skip to content

Instantly share code, notes, and snippets.

@vpeil
Last active December 21, 2015 21:18
Show Gist options
  • Save vpeil/6366853 to your computer and use it in GitHub Desktop.
Save vpeil/6366853 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
# produces a csv file, if it matches a doi
# for more information see http://search.crossref.org/help/api
use Catmandu::Sane;
use Catmandu;
use JSON;
use Catmandu::Importer::CSV;
use Catmandu::Exporter::CSV;
use Capture::Tiny 'capture';
my $url = 'http://search.crossref.org/links';
my $importer = Catmandu::Importer::CSV->new(file => "pub.csv");
my $exporter = Catmandu::Exporter::CSV->new(file => "doi.csv");
$importer->each( \&cb_request );
sub cb_request {
my $pub = $_[0];
my $cmd = "curl -X POST -d '[\"$pub->{citation}\"]' http://search.crossref.org/links --header 'Content-Type:application/json' ";
my ($response, $stderr, $return) = capture { system $cmd; };
if ($response =~ /match...true/) {
my $json = decode_json($response);
$exporter->add({
id => $pub->{id},
frontdoor => "http://pub.uni-bielefeld.de/publication/$pub->{id}",
doi => $json->{results}->[0]->{doi},
score => $json->{results}->[0]->{score},
});
}
}
#!/usr/bin/env perl
# dump your store, otherwise it will run into timeout while requesting crossref api
use Catmandu::Sane;
use Catmandu;
use Catmandu::Exporter::CSV;
Catmandu->load;
Catmandu->config;
my $bag = Catmandu->store('search')->bag('publicationItem');
my $exporter = Catmandu::Exporter::CSV->new(file => "pub.csv");
$bag->each( sub {
my $pub = $_[0];
if ($pub->{publishingYear} > 2003 && !$pub->{doiInfo}) {
$exporter->add({
id => $pub->{_id},
citation => $pub->{citation}->{ama},
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment