#!/usr/bin/perl -w
# This is a quick hack meant to replay the text pager messages
# sent across the USA on September 11th 2001 as available from
# http://911.wikileaks.org/ in approximative real-time.

use strict;
use DateTime::Format::Natural;

my $date_parser = DateTime::Format::Natural->new;
my $this_second;
my @this_second;

my $message;
my $now;

while (<>) {
	my ($date, $time, $net, $num, $code, $level);
	($date, $time, $net, $num, $code, $level, $message) = split /\s+/, $_, 7;

	$now = $date_parser->parse_datetime($date." ".$time);
	next unless defined $this_second;
	next unless DateTime->compare($now, $this_second);
	my $delay = 1/@this_second;
	print and sleep $delay for @this_second;
	undef @this_second;
} continue {
	$this_second = $now;
	push @this_second, $message;
}
