<?php
# related article: http://newtoypia.blogspot.tw/2014/08/osm-mashup.html

# wget -O /tmp/earthquakes.htm http://earthquake.usgs.gov/earthquakes/eqarchives/year/mag8/magnitude8_1900_date.php
# php earthquakes.txt /tmp/earthquakes.htm > earthquakes.json
require_once 'QueryPath/QueryPath.php';
header('Content-Type: application/json');
$home = getenv("HOME");
$qp = htmlqp($argv[1]);
$out = [];
foreach ($qp->find("tbody:nth-of-type(1) tr") as $item) {
    $date = $item->find("td:nth-of-type(1)")->text();
    $lat = $item->next()->text();
    $lon = $item->next()->text();
    $mag = $item->next()->text();
    $fatal = $item->next()->text();
    $region = $item->next()->text();
    array_push($out, array(
	'date' => $date,
	'lat' => $lat,
	'lon' => $lon,
	'mag' => $mag,
	'fatal' => $fatal,
	'region' => $region,
    ));
}
echo json_encode($out, JSON_PRETTY_PRINT);
?>
