-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateLinks.pl
68 lines (53 loc) · 1.78 KB
/
createLinks.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
#!/usr/bin/env perl
use Catmandu::Sane;
use Catmandu -load;
use Catmandu::Importer::EuropePMC;
use Net::FTP;
use Getopt::Std;
getopts('t');
our $opt_t;
Catmandu->load;
my $conf = Catmandu->config;
my $importer = Catmandu->importer;
my $exporter = Catmandu->exporter;
#generate provider.xml
my $provider = Catmandu->exporter('provider');
$provider->add({conf => $conf});
$provider->commit;
$importer->each(
sub {
my $rec = $_[0];
my $importer =
Catmandu::Importer::EuropePMC->new( query => $rec->{pmid} );
my $data = $importer->first;
if ( $data->{hitCount} == 1
&& lc $data->{resultList}->{result}->{inEPMC} eq 'n' )
{
$exporter->add( { conf => $conf, pmid => $rec->{pmid}, id => $rec->{id} } );
}
elsif ( $data->{hitCount} > 1 ) {
foreach my $item ( @{ $data->{resultList}->{result} } ) {
if ( lc $item->{source} eq 'med' && lc $item->{inEPMC} eq 'n' )
{
$exporter->add(
{ conf => $conf, pmid => $rec->{pmid}, id => $rec->{id} } );
}
}
}
}
);
$exporter->commit;
if ($opt_t) {
my $ftp = Net::FTP->new($conf->{ftp}->{host}) || die "Cannot connect: $@";
$ftp->login($conf->{ftp}->{login}, $conf->{ftp}->{pwd}) || die "Cannot login", $ftp->message;
$ftp->cwd($conf->{ftp}->{cwd}) || die "Cannot change directory", $ftp->message;
$ftp->put($conf->{exporter}->{default}->{options}->{file}) || die "Cannot put file to server", $ftp->message;;
$ftp->quit;
say "FTP upload successful.";
}
=head1 USAGE
# creates file 'pushLinks.xml'
$ perl createLinks.pl
# additionally transfers the file 'pushLinks.xml' to the ftp server
$ perl createLinks.pl -t
=cut