/usr/share/doc/libsocialtext-resting-utils-perl/examples/stu-most-wanted is in libsocialtext-resting-utils-perl 0.21-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | #!/usr/bin/perl
use strict;
use warnings;
use Socialtext::Resting::Getopt qw/get_rester/;
my $r = get_rester();
my $most_wanted_page = 'Most Wanted Pages';
warn "Fetching all pages...\n";
my @all_pages = $r->get_pages();
my %most_wanted;
my %wanters;
for my $page (@all_pages) {
next if $page eq $most_wanted_page;
warn "Fetching '$page'\n";
my @incipient = $r->get_frontlinks($page, 1);
for my $i (@incipient) {
$wanters{$page}++;
push @{ $most_wanted{$i} }, $page;
}
}
warn "Creating most wanted page...\n";
my $incipient_page_count = keys %most_wanted;
my $now = localtime;
my $page_wanters_count = keys %wanters;
my $new_page = "^^ Most Wanted Pages in " . $r->workspace . " at $now.\n"
. "There are $incipient_page_count pages wanted by $page_wanters_count other pages.\n"
. "This page is autogenerated by `stu-most-wanted`, from \"Socialtext-Resting-Utils\" "
. "<http://search.cpan.org/dist/Socialtext-Resting-Utils>\n\n"
. "| *Wanted Page* | *Count* | *Wanters* |\n";
my $max_most_wanted = 100;
for my $i ( sort { @{ $most_wanted{$b} } <=> @{ $most_wanted{$a} } }
keys %most_wanted ) {
$new_page .= "| [$i] | " . @{ $most_wanted{$i} } . " | "
. join(", ", map { "{{[$_]}}" } @{ $most_wanted{$i} })
. " |\n";
$max_most_wanted--;
last if $max_most_wanted == 0;
}
# Check if the page has changed
my $page_name = 'Most Wanted Pages';
my $prev_page = strip_date_from_page($r->get_page($page_name));
my $new_page_dateless = strip_date_from_page($new_page);
if ($prev_page ne $new_page_dateless) {
warn "Putting most wanted pages page...\n";
$r->put_page($page_name, $new_page);
}
else {
warn "Most wanted didn't change...\n";
}
exit;
sub strip_date_from_page {
my $content = shift;
$content =~ s/Most Wanted Pages in \S+ at [^.]+.//;
return $content;
}
|