browsers: improve wikimedia usage parser
[sheet.git] / tools / mkusage-wikimedia
index 901ec15c6d39b12b47ac52c22941a931ab167a6b..41ed97735c6b6d390c9f941388651550c3d91a7c 100755 (executable)
@@ -1,9 +1,10 @@
 #!/usr/bin/perl -n
-use 5.010; use strict; use warnings;
+use 5.012;
+use warnings;
 our %count;
 our $mobile;
 
-our $VERSION = '1.01';
+our $VERSION = '1.02';
 
 if (m{<td class=hl>} .. m{</?td>}) {
        $count{-source} = 'http://stats.wikimedia.org/archive/squid_reports/';
@@ -12,14 +13,20 @@ if (m{<td class=hl>} .. m{</?td>}) {
        next;
 }
 
-# select relevant columns
-/>Browser versions(.*)/ ... m{</table>} && last or next;
-my ($tr, $id, $count2, $count) = split /(?:<[^>]*>)+/;
-$mobile = $count2 !~ /non mobile/ if $id ~~ '&nbsp;';
-next if $id ~~ ['Total', '&nbsp;'];
+# select relevant data
+/>In alphabetical order/ .. eof or next;  # second table
+my ($id, $count2, $count) = map { s/<[^>]*>//gr } split /<\/td>/;
+
+# select version data
+/>Browser versions(.*)/ ... !defined $count2 or next;
+unless (defined $count2) {
+       # header row if no td separator
+       $mobile = $id !~ /non mobile/;
+       next;
+}
 
 # convert to usable syntax
-my ($browser, $version) = split /\h+/, $id, 2;
+my ($browser, $version) = split /\h+/, $id || ' ', 2;
 $count =~ s/,//g;
 $count =~ s/%$//;
 $version //= 0;