Author: dom Date: 2006-04-08 10:03:14 +0100 (Sat, 08 Apr 2006) New Revision: 760
Modified: utils/get-guide-versions Log: Support DOAP
Modified: utils/get-guide-versions =================================================================== --- utils/get-guide-versions 2006-04-08 03:50:54 UTC (rev 759) +++ utils/get-guide-versions 2006-04-08 09:03:14 UTC (rev 760) @@ -4,7 +4,8 @@
use strict; use warnings; -use WWW::Mechanize; +use XML::Simple; +use LWP::UserAgent;
my $out = "/srv/www/dev.openguides.org/html/static/versions.html";
@@ -25,28 +26,51 @@ 'Victoria, BC' => 'http://victoria.openguides.org/', 'Boston, MA' => 'http://boston.openguides.org/', 'Saint Paul, MN' => 'http://saintpaul.openguides.org/', - 'The Tourist Engineer' => 'http://engineer.openguides.org/' + 'The Tourist Engineer' => 'http://engineer.openguides.org/', + "Earle's testing" => 'http://openguides.org/testing/' );
-my $mech = WWW::Mechanize->new(agent => "OpenGuides get-guide-versions", - autocheck => 1); +my $ua = LWP::UserAgent->new(agent => "OpenGuides get-guide-versions");
open OUT, ">$out" or die $!;
print OUT "<html><head><title>Versions of OpenGuides in use</title></head>\n"; -print OUT "<body><table>\n"; +print OUT "<body>\n"; +print OUT "Last updated: " . scalar(localtime(time)) . "\n"; +print OUT "<table>\n";
-foreach my $guide (keys %guides) { +foreach my $guide (sort keys %guides) { print OUT "<tr><td><a href="$guides{$guide}">$guide</td><td>"; - $mech->add_header( Referer => undef ); - $mech->get($guides{$guide}); - my $content = $mech->content; - if ($content =~ /version.(0.\d+)/s) { - print OUT $1; - } else { - print OUT "Not found"; + + # Try DOAP + my $success = 0; + my $response = $ua->get("$guides{$guide}?action=about;format=rdf"); + if ($response->is_success) { + my $doap = eval { XMLin($response->content)} ; + if ($@) { + # fall through + } else { + if (my $version = eval { $doap->{Project}->{release}->{Version}->{revision} }) { + print OUT "$version (DOAP)"; + $success++; + } + } } - print OUT "</td></tr>\n"; + if ($success == 0) { + $response = $ua->get($guides{$guide}); + if ($response->is_success) { + my $content = $response->content; + if ($content =~ /version.(0.\d+)/s) { + print OUT $1; + } else { + print OUT "Not found"; + } + print OUT " (HTML)"; + } else { + print "No methods worked"; + } + print OUT "</td></tr>\n"; + } }
print OUT "</table></body></html>\n";
openguides-commits@lists.openguides.org