<?php
date_default_timezone_set('Europe/London');
$text=file_get_contents('techhistory.txt');

//March 30, 24 BC -
$matches=array();
preg_match_all('/\w+\s+\w+,\s+\w+\s+\-\s+.*\n/',$text,$matches);
unlink('tdit.db');
if ($db = new SQLite3('tdit.db')) $db->query('CREATE TABLE tdit (id int, year int, month int , day int, event text, PRIMARY KEY (id));');


foreach ($matches as $match) {
	$i=0;
	foreach ($match as $m){
		preg_match('/\w+\s+\w+,\s+\w+\s+/',$m,$dt);
		$strdt=date("Y-m-d",strtotime($dt[0]));

		$year=date("Y",strtotime($dt[0]));
		$month=date("m",strtotime($dt[0]));
		$day=date("d",strtotime($dt[0]));

		$m=preg_replace('/"/','',$m);

		$op=chop(substr($m,strlen($dt[0])));
		$op=preg_replace('/\-\s+/','',$op);

		$q="INSERT INTO \"tdit\" VALUES($i,$year,$month,$day,\"$op\");";
		$db->query($q) or die('whoops\n');

		print $q."\n";

		$i++;
	}
}

$db->close();
?>