-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery.pl
executable file
·79 lines (64 loc) · 1.49 KB
/
query.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env perl
# PODNAME: query-crossref
# ABSTRACT: Query CrossRef
# Vim:
# :exe ".-1r!query.pl --title '" . getline('.') . "'"
use FindBin;
use lib "$FindBin::Bin/../lib";
use Modern::Perl;
package Q {
use Mu;
use CLI::Osprey;
#use Log::Any::Adapter( 'File', './log.txt', 'log_level'=> 'info');
use Renard::Incunabula::Common::Setup;
use Renard::Block::Metadata::CrossRef;
use Renard::Block::Metadata::DOI;
use utf8::all;
lazy email => method() {
chomp(my $email = `git config user.email`);
die "No e-mail in .gitconfig" unless $email;
$email;
};
lazy crossref => method() {
Renard::Block::Metadata::CrossRef->new(
email => $self->email,
);
};
lazy doi => method() {
Renard::Block::Metadata::DOI->new;
};
option title => (
is => 'ro',
required => 1,
format => 's',
doc => 'Article title'
);
method run() {
my $cr = $self->crossref;
my $num_of_results = 1;
$cr->rows(1);
my $data = $cr->query_bibliographic( $self->title, "title,DOI,URL" );
my $count = 0;
while () {
last unless $data;
for my $row (@$data) {
print "\n" unless ($row);
for my $field (sort keys %$row) {
print $field, ": ", $row->{$field}. "\n";
if( $field eq 'URL' ) {
my $content = $self->doi->get_bibtex( $row->{$field} );
$content =~ s/\n+\Z//sm;
say $content;
}
}
}
last if ++$count >= $num_of_results;
$data = $cr->get_next();
}
}
}
sub main {
binmode STDOUT, ":encoding(UTF-8)";
Q->new_with_options->run;
}
main;