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

# wget -O /tmp/haunted-1.htm 'http://www.poidb.com/groups/view-poi.asp?groupid=409&r=&f=&searchfor=&ll=&loc=&region=2_62&page=1'
# php haunted.txt /tmp/haunted-1.htm > haunted-1.json
# repeat for page=2 and page=3
# combine haunted-[123].json into one single file haunted.json
require_once 'QueryPath/QueryPath.php';
header('Content-Type: application/json');
$home = getenv("HOME");
$qp = htmlqp($argv[1]);
$out = [];
foreach ($qp->find("span.fn > a") as $item) {
    $url = "http://www.poidb.com" . $item->attr("href");
    $name = $item->parent()->text();
    $lat_lon = $item->next("strong")->text();
    preg_match("/Latitude:(\S+) Longitude:(\S+)/", $lat_lon, $matches);
    array_push($out, array(
	'url' => $url,
	'name' => $name,
	'lat' => $matches[1],
	'lon' => $matches[2],
    ));
}
echo json_encode($out, JSON_PRETTY_PRINT);
?>
