Created
May 27, 2009 11:51
-
-
Save hidek/118605 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| use strict; | |
| use warnings; | |
| use Web::Scraper; | |
| use HTML::TreeBuilder::LibXML; | |
| use URI; | |
| use Chart::Clicker; | |
| use Chart::Clicker::Data::DataSet; | |
| use Chart::Clicker::Data::Series; | |
| use Chart::Clicker::Renderer::Pie; | |
| my $dist = scraper { | |
| process '//select[@name="distribution"][1]/option', | |
| 'dist[]' => {name => 'TEXT', tag => '@value'}; | |
| }; | |
| my $dist_ver = scraper { | |
| process '//tr[th/text()="Feature"]/td', | |
| 'version[]' => 'TEXT', | |
| process '//tr[th/a/text()="perl"]/td', | |
| 'perl[]' => 'TEXT', | |
| ; | |
| }; | |
| my $res = $dist->scrape(URI->new('http://distrowatch.com/search.php')); | |
| my %stats; | |
| for my $val (@{$res->{dist}}) { | |
| my $tag = $val->{tag} or next; | |
| my $table = $dist_ver->scrape( | |
| URI->new("http://distrowatch.com/table.php?distribution=$tag")); | |
| if ($table->{version}) { | |
| warn $val->{name}; | |
| my $ver = $table->{perl}->[0] || 'none'; | |
| $ver = 'none' unless $ver =~ qr/5.+/; | |
| $stats{$ver}++; | |
| } | |
| } | |
| my $cc = Chart::Clicker->new(width => 500, height => 400); | |
| my @series; | |
| my @table; | |
| for (sort {$stats{$b} <=> $stats{$a}} keys %stats) { | |
| push @series, Chart::Clicker::Data::Series->new( | |
| keys => [1], | |
| values => [$stats{$_}], | |
| name => $_, | |
| ); | |
| push @table, "<tr><td>$_</td><td>" . $stats{$_} . '</td></tr>'; | |
| } | |
| my $ds = Chart::Clicker::Data::DataSet->new(series => \@series); | |
| $cc->add_to_datasets($ds); | |
| my $defctx = $cc->get_context('default'); | |
| $defctx->renderer(Chart::Clicker::Renderer::Pie->new); | |
| $defctx->domain_axis->hidden(1); | |
| $defctx->range_axis->hidden(1); | |
| $cc->plot->grid->visible(0); | |
| $cc->draw; | |
| $cc->write('chart.png'); | |
| print "<table>\n"; | |
| for (@table) { | |
| print "$_\n"; | |
| } | |
| print "</table>\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment