| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | use strict; |
|---|
| 6 | use warnings; |
|---|
| 7 | use XML::Simple; |
|---|
| 8 | use LWP::UserAgent; |
|---|
| 9 | |
|---|
| 10 | my $out = "/srv/www/dev.openguides.org/html/static/versions.html"; |
|---|
| 11 | |
|---|
| 12 | my %guides = ( Birmingham => 'http://birmingham.openguides.org/', |
|---|
| 13 | Cambridge => 'http://cambridge.openguides.org/', |
|---|
| 14 | Cotswolds => 'http://cotswolds.openguides.org/', |
|---|
| 15 | Glasgow => 'http://glasgow.openguides.org/', |
|---|
| 16 | Lancaster => 'http://lancaster.openguides.org/', |
|---|
| 17 | London => 'http://london.openguides.org/', |
|---|
| 18 | Manchester => 'http://manchester.openguides.org/', |
|---|
| 19 | 'Randomness (London)' => 'http://london.randomness.org.uk/', |
|---|
| 20 | 'Milton Keynes' => 'http://miltonkeynes.openguides.org/', |
|---|
| 21 | Norwich => 'http://norwich.openguides.org/', |
|---|
| 22 | Nottingham => 'http://nottingham.openguides.org/', |
|---|
| 23 | Oxford => 'http://oxford.openguides.org/', |
|---|
| 24 | 'Vegan Oxford' => 'http://the.earth.li/~kake/cgi-bin/openguides/vegan-oxford.cgi', |
|---|
| 25 | 'Reading' => 'http://reading.openguides.org/', |
|---|
| 26 | Southampton => 'http://southampton.openguides.org/', |
|---|
| 27 | Vienna => 'http://vienna.openguides.org/', |
|---|
| 28 | Brussels => 'http://www.justbiit.com/cgi-bin/openguides/', |
|---|
| 29 | 'Montreal, QC' => 'http://montreal.openguides.org/', |
|---|
| 30 | 'Victoria, BC' => 'http://victoria.openguides.org/', |
|---|
| 31 | 'Boston, MA' => 'http://boston.openguides.org/', |
|---|
| 32 | 'Saint Paul, MN' => 'http://saintpaul.openguides.org/', |
|---|
| 33 | 'New York' => 'http://newyork.openguides.org/myguide/wiki.cgi', |
|---|
| 34 | 'The Tourist Engineer' => 'http://engineer.openguides.org/', |
|---|
| 35 | ); |
|---|
| 36 | |
|---|
| 37 | my $ua = LWP::UserAgent->new(agent => "OpenGuides get-guide-versions"); |
|---|
| 38 | |
|---|
| 39 | open OUT, ">$out" or die $!; |
|---|
| 40 | |
|---|
| 41 | print OUT "<html><head><title>Versions of OpenGuides in use</title></head>\n"; |
|---|
| 42 | print OUT "<body>\n"; |
|---|
| 43 | print OUT "Last updated: " . scalar(localtime(time)) . "\n"; |
|---|
| 44 | print OUT "<table>\n"; |
|---|
| 45 | |
|---|
| 46 | foreach my $guide (sort keys %guides) { |
|---|
| 47 | print OUT "<tr><td><a href=\"$guides{$guide}\">$guide</td><td>"; |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | my $success = 0; |
|---|
| 51 | my $response = $ua->get("$guides{$guide}?action=about;format=rdf"); |
|---|
| 52 | if ($response->is_success) { |
|---|
| 53 | my $doap = eval { XMLin($response->content)} ; |
|---|
| 54 | if ($@) { |
|---|
| 55 | |
|---|
| 56 | } else { |
|---|
| 57 | if (my $version = eval { $doap->{Project}->{release}->{Version}->{revision} }) { |
|---|
| 58 | print OUT "$version (DOAP)"; |
|---|
| 59 | $success++; |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | } |
|---|
| 63 | if ($success == 0) { |
|---|
| 64 | $response = $ua->get($guides{$guide}); |
|---|
| 65 | if ($response->is_success) { |
|---|
| 66 | my $content = $response->content; |
|---|
| 67 | if ($content =~ /version.(0\.\d+(-\w+)?)/s) { |
|---|
| 68 | print OUT $1; |
|---|
| 69 | } else { |
|---|
| 70 | print OUT "Not found"; |
|---|
| 71 | } |
|---|
| 72 | print OUT " (HTML)"; |
|---|
| 73 | } else { |
|---|
| 74 | print OUT "No methods worked"; |
|---|
| 75 | } |
|---|
| 76 | print OUT "</td></tr>\n"; |
|---|
| 77 | } |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | print OUT "</table></body></html>\n"; |
|---|
| 81 | |
|---|
| 82 | close OUT; |
|---|