FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
py4e/tools/python-data/geo_test.php at master · GHubPythonProjects/py4e · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
GHubPythonProjects
/
py4e
Public
forked from
csev/py4e
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
py4e
/
tools
/
python-data
/
geo_test.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
52 lines (46 loc) · 1.76 KB
Breadcrumbs
py4e
/
tools
/
python-data
/
geo_test.php
Copy path
File metadata and controls
52 lines (46 loc) · 1.76 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
.
'
?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"
);
Back
|
FazBrowse Home
|
New Git URL