forked from csev/py4e
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeo_test.php
More file actions
52 lines (46 loc) · 1.77 KB
/
geo_test.php
File metadata and controls
52 lines (46 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
require_once "../config.php";
require_once "data/data_util.php";
require_once "data/names.php";
require_once "data/locations.php";
use \Tsugi\Core\LTIX;
use \Tsugi\Util\LTI;
use \Tsugi\Util\Net;
$LAUNCH = 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(LTI::jsonIndent($sample_data));
continue;
}
// echo("<pre>\n");echo(\Tsugi\Util\LTI::jsonIndent(json_encode($sample_json)));echo("</pre>\n");
if ( !isset($sample_json->results[0]->place_id) ) {
echo("*** Could not find place_id $location\n");
// echo(\Tsugi\Util\LTI::jsonIndent($sample_data));
continue;
}
$sample_place = $sample_json->results[0]->place_id;
echo("location=$location place=$sample_place\n");
if ( $i-- < 1 ) break;
}
echo("</pre>\n");