From 0fe80bb9ec75e242d97d296b1fa3e0394daa1c15 Mon Sep 17 00:00:00 2001 From: Mickey Nasriachi Date: Wed, 11 Sep 2024 22:21:18 +0200 Subject: [PATCH] mickey/river --- bin/river.pl | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 bin/river.pl diff --git a/bin/river.pl b/bin/river.pl new file mode 100644 index 0000000..5a02d48 --- /dev/null +++ b/bin/river.pl @@ -0,0 +1,57 @@ +use strict; +use warnings; +use v5.36; + +use Cpanel::JSON::XS qw< decode_json >; +use Getopt::Long; + +use MetaCPAN::Logger qw< :log :dlog >; + +use MetaCPAN::ES; +use MetaCPAN::Ingest qw< read_url >; + +# setup +my $river_url //= 'https://neilb.org/river-of-cpan.json.gz'; +my $river_data = decode_json( read_url($river_url) ); + +my $es = MetaCPAN::ES->new( index => "cpan", type => "distribution" ); +my $bulk = $es->bulk(); + +log_info {'Updating the distribution index'}; + +for my $data ( @{$river_data} ) { + my $dist = delete $data->{dist}; + + $bulk->update( { + id => $dist, + doc => { + name => $dist, + river => $data, + }, + doc_as_upsert => 1, + } ); +} + +$bulk->flush; + +1; + +__END__ + +=pod + +=head1 SYNOPSIS + + # bin/metacpan river + +=head1 DESCRIPTION + +Retrieves the CPAN river data from its source and +updates our ES information. + +This can then be accessed here: + +http://fastapi.metacpan.org/v1/distribution/Moose +http://fastapi.metacpan.org/v1/distribution/HTTP-BrowserDetect + +=cut