require_once "names.php"; require_once "locations.php"; use Tsugi\Core\LTIX; use Tsugi\Util\LTI; use Tsugi\Util\Net; $LTI = LTIX::requireData(); $p = $CFG->dbprefix; if (!$USER->instructor) { die('Must be instructor'); } $sanity = array('urllib' => 'You should use urllib to retrieve the data from the API', 'urlencode' => 'You should use urlencode add parameters to the API url', 'json' => 'You should use the json library to parse the API data'); echo "<pre>\n"; echo "Running test...\n"; // Run though all the locations // var_dump($LOCATIONS); $url = LTIX::curPageUrlScript(); $i = 500; foreach ($LOCATIONS as $key => $location) { // echo(htmlentities($location)."\n"); $api_url = str_replace('geo_test.php', 'data/geojson', $url); $sample_url = $api_url . '?sensor=false&address=' . urlencode($location); $sample_data = Net::doGet($sample_url); $sample_count = strlen($sample_data); $response = Net::getLastHttpResponse(); $sample_json = json_decode($sample_data); if ($response != 200 || $sample_json == null || !isset($sample_json->results[0])) { echo "*** Bad response={$response} url={$sample_url} json_error=" . json_last_error_msg() . "\n"; echo jsonIndent($sample_data); continue; } // echo("<pre>\n");echo(jsonIndent(json_encode($sample_json)));echo("</pre>\n");
function dataUrl($file) { global $GLOBAL_PYTHON_DATA_URL; if (is_string($GLOBAL_PYTHON_DATA_URL)) { return $GLOBAL_PYTHON_DATA_URL . $file; } $url = LTIX::curPageUrlScript(); $retval = str_replace('index.php', 'data/' . $file, $url); return $retval; }