Permalink
Browse files

add script to be used in a cron-job that will periodically refresh so…

…me data from MetaCPAN API
  • Loading branch information...
szabgab committed Oct 21, 2014
1 parent 1adde75 commit 77619bd404df5733573871990294ac436468934c
Showing with 65 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +3 −0 Makefile.PL
  3. +10 −0 bin/fetch.pl
  4. +51 −0 lib/MetaCPAN/SCO/Fetch.pm
View
@@ -3,3 +3,4 @@
/blib/
/pm_to_blib
*.swp
/totals.json
View
@@ -11,6 +11,9 @@ my %conf = (
'File::Basename' => '0',
'Plack::Request' => '0',
'Template' => '0',
'LWP::Simple' => '0',
'JSON' => '0',
'Path::Tiny' => '0',
},
);
View
@@ -0,0 +1,10 @@
#!/usr/bin/perl
use strict;
use warnings;
use Cwd qw(abs_path);
use File::Basename qw(dirname);
use MetaCPAN::SCO::Fetch;
MetaCPAN::SCO::Fetch->run( dirname(dirname( abs_path(__FILE__) )));
View
@@ -0,0 +1,51 @@
package MetaCPAN::SCO::Fetch;
use strict;
use warnings;
use LWP::Simple qw(get);
use JSON qw(from_json to_json);
use Path::Tiny qw(path);
=pod
TODO: Once we are sure these are the correct queries, add them to https://github.com/CPAN-API/cpan-api/wiki/API-docs
curl -XPOST api.metacpan.org/v0/author/_search -d '{
"query": { "match_all": {} },
"size":0
}'
curl http://api.metacpan.org/v0/author/_search?size=0
curl -XPOST api.metacpan.org/v0/distribution/_search -d '{
"query": { "match_all": {} },
"size":0
}'
curl http://api.metacpan.org/v0/distribution/_search?size=0
curl -XPOST api.metacpan.org/v0/module/_search -d '{
"query": { "match_all": {} },
"size":0
}'
curl http://api.metacpan.org/v0/module/_search?size=0
=cut
sub run {
my ($self, $root) = @_;
my %totals;
foreach my $name (qw(author distribution module)) {
my $json = get "http://api.metacpan.org/v0/$name/_search?size=0";
my $data = from_json $json;
$totals{$name} = $data->{hits}{total};
}
path("$root/totals.json")->spew_utf8(to_json \%totals);
return;
}
1;

0 comments on commit 77619bd

Please sign in to comment.