#!/usr/local/bin/perl -w use strict; use DBD::SQLite; use DateTime::Format::SQLite; my( $home ) = glob "~"; my $dbfile = "$home/.local/share/" . "zeitgeist/activity.sqlite"; my $dbh = DBI->connect( "dbi:SQLite:dbname=$dbfile", "", "" ); my $sth = $dbh->prepare( "SELECT datetime(substr(timestamp,1,10), 'unixepoch') AS time FROM event WHERE time >= datetime('now', '-24 hours')" ); $sth->execute(); my %activity = (); while( my( $time ) = $sth->fetchrow_array() ) { my $dt = DateTime::Format::SQLite-> parse_datetime( $time ); $dt->set_time_zone( "local" ); $activity{ $dt->hour() }++; } my $now = DateTime->now( time_zone => "local" ); my $dt = $now->clone->subtract( days => 1 ); while( $dt < $now ) { my $hour = $dt->hour(); printf "%02d:00 %d\n", $hour, $activity{ $hour } || 0; $dt = $dt->add( hours => 1 ); }