50 lines
944 B
Plaintext
50 lines
944 B
Plaintext
|
#!/usr/bin/perl
|
||
|
|
||
|
use strict;
|
||
|
use warnings;
|
||
|
use v5.14;
|
||
|
|
||
|
use DBI;
|
||
|
use POSIX qw(strftime);
|
||
|
|
||
|
my $dbh = DBI->connect("dbi:SQLite:dbname=rss2html.sqlite", "", "");
|
||
|
$dbh->{sqlite_unicode} = 1;
|
||
|
my $feed_id = $ARGV[0];
|
||
|
my $issued
|
||
|
= $dbh->selectcol_arrayref(
|
||
|
"select issued from items where feed_id=? order by issued", {}, $feed_id
|
||
|
);
|
||
|
|
||
|
my @dt;
|
||
|
for (1 .. $#{$issued}) {
|
||
|
push @dt, $issued->[$_] - $issued->[$_-1];
|
||
|
}
|
||
|
@dt = sort { $a <=> $b } @dt;
|
||
|
my $c = 0;
|
||
|
for (@dt) {
|
||
|
$c++;
|
||
|
printf("%14s %8d %5.1f%%\n", hr($_), $_, $c * 100 / @dt);
|
||
|
}
|
||
|
|
||
|
sub hr {
|
||
|
my ($s) = $_;
|
||
|
my $hr = "";
|
||
|
if ($s > 86400) {
|
||
|
my $d = int ($s / 86400);
|
||
|
$hr .= $d . "d";
|
||
|
$s -= $d * 86400;
|
||
|
}
|
||
|
if ($hr || $s > 3600) {
|
||
|
my $h = int ($s / 3600);
|
||
|
$hr .= sprintf("%02dh", $h);
|
||
|
$s -= $h * 3600;
|
||
|
}
|
||
|
if ($hr || $s > 60) {
|
||
|
my $m = int ($s / 60);
|
||
|
$hr .= sprintf("%02dm", $m);
|
||
|
$s -= $m * 60;
|
||
|
}
|
||
|
$hr .= sprintf("%02ds", $s);
|
||
|
return $hr;
|
||
|
}
|