示例#1
0
<?php

require '../vendor/autoload.php';
date_default_timezone_set('America/Toronto');
$routes = json_decode(file_get_contents(__DIR__ . '/../data/routes.json'));
$list = new \LondonLive\CSVStopList();
$list->readFile('stops.csv');
$scrape_webwatch = false;
$scrape_stopids = false;
if ($scrape_webwatch) {
    $fetcher = new LondonLive\StopTimesParser(new LondonLive\HTTPStopTimesFetcher());
    $routes = json_decode(file_get_contents(__DIR__ . '/../data/routes.json'));
    $fetch_time = time();
    foreach ($routes->routes as $route) {
        echo "Fetching WebWatch data for {$route->id}\n";
        $route_data = $fetcher->get($route->id);
        foreach ($route_data['stops'] as $stop) {
            $csvStop = $list->getStop($stop['number']);
            $csvStop->latitude = $stop['latitude'];
            $csvStop->longitude = $stop['longitude'];
            $csvStop->name_webwatch = $stop['name'];
        }
        file_put_contents(__DIR__ . "/../tempdata/data-{$fetch_time}-{$route->id}.txt", json_encode($route_data));
    }
}
/**
 * Returns the rows as an array of an array of strings from the
 * first table in the document.
 *
 * @param DOMDocument $dom
 */
示例#2
0
<?php

require '../vendor/autoload.php';
date_default_timezone_set('America/Toronto');
header('Content-Type: application/json');
$fetcher = new LondonLive\StringStopTimesFetcher(file_get_contents('data-02.txt'));
$parser = new LondonLive\StopTimesParser($fetcher);
echo json_encode($parser->get('04'), JSON_PRETTY_PRINT);