Skip to content

Instantly share code, notes, and snippets.

@y-yu
Created August 16, 2011 14:10
Show Gist options
  • Save y-yu/1149175 to your computer and use it in GitHub Desktop.
Save y-yu/1149175 to your computer and use it in GitHub Desktop.
表示してる部分。かなり手抜き。
use strict;
use warnings;
use DBIx::Simple;
use CGI;
use DateTime::Format::SQLite;
use DateTime;
use Text::Xslate qw(mark_raw);
my $q = CGI->new;
print $q->header(-charset=>'utf-8');
my ($users, $times) = get_data();
my @times = sort (keys %$times);
my $today = DateTime->today( time_zone => 'Asia/Tokyo' );
my $tx = Text::Xslate->new();
my $vars = {
today => $today->strftime('%Y/%m/%d'),
times => \@times,
users => $users,
};
print $tx->render('./view.html', $vars);
sub get_data {
my $date = DateTime::Format::SQLite->format_date( DateTime->now );
my $db = DBIx::Simple->connect('dbi:SQLite:dbname=whologin.db');
my $rs = $db->query('SELECT name, user_id, host, created_at FROM whologin WHERE created_at LIKE ? ORDER BY user_id', $date.'%');
my $users;
my %times;
while ( my $row = $rs->hash ) {
my $dt = DateTime::Format::SQLite->parse_datetime($row->{created_at});
$dt->set_time_zone('Asia/Tokyo');
my $ca = $dt->strftime('%H:%M');
my $id = $row->{user_id};
$times{$ca} = 1;
$users->{$id}->{name} = $row->{name};
push @{ $users->{$id}->{times}->{$ca} }, $row->{host};
}
$db->disconnect;
return $users, \%times;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment