Created
February 12, 2018 21:34
-
-
Save rage311/9157727d7fbab6d4fdf090f57f6424d7 to your computer and use it in GitHub Desktop.
Script to query freshports.org for ports by name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use 5.024; | |
use Mojo::UserAgent; | |
use Data::Dumper; | |
die 'Need port name as argument' | |
unless (my $port_name = $ARGV[0]); | |
chomp $port_name; | |
my $ua = Mojo::UserAgent->new(); | |
my $result = $ua->get( | |
'https://www.freshports.org/search.php', | |
form => { | |
stype => 'name', | |
method => 'match', | |
query => $port_name, | |
num => '50', | |
orderby => 'category', | |
orderbyupdown => 'asc', | |
search => 'Search', | |
format => 'html', | |
branch => 'head', | |
})->result; | |
my %matches = $result | |
->dom | |
->find('dl > dt') | |
->map(sub { | |
$_->at('big > b > a')->text => { | |
origin => $_->at('big > b > a')->attr('href') =~ s#(^/|/$)##gr, | |
desc => $_->at('span.fp_description_short')->text, | |
ver => $_->at('span ~ br ~ b')->text =~ s/^ +//r, | |
cat => $_->at('span ~ br ~ b ~ a')->text =~ s/^ +//r, | |
}; | |
}) | |
->each; | |
die "No matches" unless (%matches); | |
printf "%s\n\n", join("\n ", $_, @{$matches{$_}}{qw(ver desc origin cat)}) | |
for sort keys %matches; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment