=================================================================== RCS file: /cvs/openbsd/errata_scraper/errata_scraper.pl,v retrieving revision 1.1 retrieving revision 1.4 diff -u -r1.1 -r1.4 --- openbsd/errata_scraper/errata_scraper.pl 2011/03/21 17:26:58 1.1 +++ openbsd/errata_scraper/errata_scraper.pl 2011/05/29 02:04:30 1.4 @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $AFresh1$ +# $AFresh1: errata_scraper.pl,v 1.3 2011/03/23 18:46:16 andrew Exp $ ######################################################################## # Copyright (c) 2011 Andrew Fresh # @@ -18,38 +18,32 @@ use strict; use warnings; -use Mojo::Client; -my $client = Mojo::Client->new; - -$client->get( - 'http://www.openbsd.org/errata48.html' => sub { - shift->res->dom('li')->each( - sub { - my $e = shift; - - my $patch = $e->at('a[href$=".patch"]')->attrs->{href}; - - my $title = $e->at('strong')->replace('')->all_text; - $title =~ s/\s+/ /gxms; - - my $arch = $e->at('i')->replace('')->all_text; - $arch =~ s/\s+/ /gxms; - - # the li ends at p, but the parser expects a /li - $e->at('p')->replace(''); - - my $descr = $e->all_text; - $descr =~ s/\s+/ /gxms; - $descr =~ s/^\s+|\s+$//gxms; - - print 'Title: ', $title, "\n"; - print 'Arch: ', $arch, "\n"; - print 'Patch: ', $patch, "\n"; - print 'Descr: ', $descr, "\n"; - print "\n"; - } - ); +use Mojo::UserAgent; + +my $base_uri = 'http://www.openbsd.org/'; + +my $ua = Mojo::UserAgent->new; + +my $ls = $ua->get( $base_uri . 'errata.html' )->res->dom('a[href^="errata"]'); + +foreach my $l ( @{$ls}[ -2, -1 ] ) { + print 'Errata for OpenBSD ', $l->text, "\n"; + foreach my $e ( + reverse @{ $ua->get( $base_uri . $l->attrs->{'href'} )->res->dom('li') + } ) + { + my $patch = $e->at('a[href$=".patch"]')->replace('')->{href}; + my $title = $e->at('strong')->replace('')->all_text; + my $arch = $e->at('i')->replace('')->all_text; + my $descr = $e->all_text; + $descr =~ s/\s+/ /gs; + $descr =~ s/\s(\.(?:\s|$))/$1/gs; + $descr =~ s/\.+$/./gs; + + print 'Title: ', $title, "\n"; + print 'Arch: ', $arch, "\n"; + print 'Patch: ', $patch, "\n"; + print 'Descr: ', $descr, "\n"; + print "\n"; } -); - -$client->start; +}