From ab90d999af98f1db32e289d6d1bc8d61881f6a4a Mon Sep 17 00:00:00 2001 From: Paul Wise Date: Sat, 21 Nov 2015 11:18:41 +0000 Subject: Fix website hit stats and translation prioritization (Closes: #791678) CVS version numbers get-www-stats: 1.5 -> 1.6 stattrans.pl: 1.115 -> 1.116 arabic/po/stats.ar.po: 1.2 -> 1.3 bulgarian/po/stats.bg.po: 1.15 -> 1.16 chinese/po/stats.zh.po: 1.3 -> 1.4 danish/po/stats.da.po: 1.7 -> 1.8 dutch/po/stats.nl.po: 1.7 -> 1.8 finnish/po/stats.fi.po: 1.4 -> 1.5 french/po/stats.fr.po: 1.8 -> 1.9 galician/po/stats.gl.po: 1.2 -> 1.3 german/po/stats.de.po: 1.11 -> 1.12 italian/po/stats.it.po: 1.8 -> 1.9 japanese/po/stats.ja.po: 1.8 -> 1.9 norwegian/po/stats.nb.po: 1.4 -> 1.5 polish/po/stats.pl.po: 1.6 -> 1.7 portuguese/po/stats.pt.po: 1.11 -> 1.12 russian/po/stats.ru.po: 1.6 -> 1.7 slovak/po/stats.sk.po: 1.3 -> 1.4 spanish/po/stats.es.po: 1.6 -> 1.7 swedish/po/stats.sv.po: 1.4 -> 1.5 --- stattrans.pl | 61 ++++++++++++------------------------------------------------ 1 file changed, 12 insertions(+), 49 deletions(-) (limited to 'stattrans.pl') diff --git a/stattrans.pl b/stattrans.pl index 4565e56c755..c20bc121acc 100755 --- a/stattrans.pl +++ b/stattrans.pl @@ -28,18 +28,7 @@ use Webwml::TransCheck; use Webwml::TransIgnore; use Debian::L10n::Db ('%LanguageList'); use Net::Domain qw(hostfqdn); - -BEGIN { - $dde_available = 0; - eval { - require JSON; - require LWP::Simple; - LWP::Simple->import; - $dde_available = 1; - }; if ($@) { - warn "One or more modules required for DDE support failed to load: $@\n"; - } -} +use JSON; $| = 1; @@ -52,8 +41,8 @@ $opt_v = 0; $opt_d = "u"; $opt_l = undef; $opt_b = ""; # Base URL, if not debian.org -# URL of JSON data or path to plaintext file with lines: "1299999 /doc/index\n" -$opt_f = "http://dde.debian.net/dde/q/static/porridge/stats?t=json"; +# path of web stats JSON data +$opt_f = "/srv/www.debian.org/webwml/stats.json"; getopts('h:w:b:p:t:vd:l:f:') || die; # Replace filename globbing by Perl regexps $opt_p =~ s/\./\\./g; @@ -323,43 +312,20 @@ mkdir ($config{'htmldir'}, 02775) if (! -d $config{'htmldir'}); # Read website hit statistics, if available my %hits; -my $hits_hostname; -my $hits_datetime; my $file_sorter = sub($$) { $_[0] cmp $_[1] }; -if ($config{'hit_file'} and $config{'hit_file'} =~ m{^(f|ht)tps?://} and ! $dde_available) { - warn "Disabling fetching of hit data.\n"; - $config{'hit_file'} = undef; -} if ($config{'hit_file'}) { - if ($config{'hit_file'} =~ m{^(f|ht)tps?://}) { - printf("Retrieving hit data from [%s].\n", $config{'hit_file'}) if ($config{'verbose'}); - my $json = LWP::Simple::get($config{'hit_file'}); - if ($json) { - my $perl = JSON::from_json($json, {utf8 => 1}); - my %metadata = %{$perl->{'m'}}; - $hits_hostname = $metadata{'hostname'} || undef; - $hits_datetime = defined $metadata{'Last-Modified'} ? strftime "%Y-%m-%d %T GMT", gmtime $metadata{'Last-Modified'} : undef; - foreach my $e (@{$perl->{'r'}}) { - my ($count, $url) = @$e; - last if $count < 3; # URLS with 2 or 1 hits are most likely mistakes; let's not waste RAM on them - $hits{substr($url, 1)} = $count; - } - } else { - warn "Retrieving hit data failed.\n"; - } - } else { - $hits_hostname = hostfqdn; - $hits_datetime = strftime "%Y-%m-%d %T %Z", localtime; - open(HITS, $config{'hit_file'}) or die sprintf("Opening hit file [%s] failed: $!", $config{'hit_file'}); - printf "Reading hit file [%s]\n", $config{'hit_file'} if ($config{'verbose'}); - foreach my $hit_line () { - chomp $hit_line; - $hit_line =~ /^\s*(\d+)\s+(.*)/ or warn sprintf("unrecognized hit file [%s] line [%s]", $config{'hit_file'}, $hit_line); - my ($count, $url) = ($1, $2); + printf("Retrieving hit data from [%s].\n", $config{'hit_file'}) if ($config{'verbose'}); + open( my $fh, '<', $config{'hit_file'} ); + local $/; + my $json = <$fh>; + close $fh; + if ($json) { + my $perl = JSON::from_json($json, {utf8 => 1}); + foreach my $e (@{$perl}) { + my ($count, $url) = @$e; last if $count < 3; # URLS with 2 or 1 hits are most likely mistakes; let's not waste RAM on them $hits{substr($url, 1)} = $count; } - close(HITS) or die sprintf("Closing hit file [%s] failed: $!", $config{'hit_file'}); } if (%hits) { $file_sorter = sub($$) { @@ -593,9 +559,6 @@ foreach $lang (@search_in) { print HTML "\n"; if (%hits) { print HTML '

Note: the lists of pages are sorted by popularity. Hover over the page name to see the number of hits.'; - if (defined $hits_hostname and defined $hits_datetime) { - printf HTML ' ', $hits_hostname, $hits_datetime; - } print HTML "

\n"; } -- cgit v1.2.3