X Tutup
'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' ); $api_url = dataUrl('opengeo'); // Compute the stuff for the output $code = 42; $sample = load_opengeo(42, $api_url); $sample_location = $sample[0]; $sample_plus = $sample[1]; $sample_count = $sample[2]; $sample_url = $sample[3]; $code = $USER->id+$LINK->id+$CONTEXT->id; $actual = load_opengeo($code, $api_url); $actual_location = $actual[0]; $actual_place = $actual[1]; $actual_count = $actual[2]; $actual_url = $actual[3]; $oldgrade = $RESULT->grade; if ( isset($_POST['plus_code']) && isset($_POST['code']) ) { $RESULT->setJsonKeys( array( 'code' => $_POST['code'], 'plus_code' => $_POST['plus_code'], 'actual_url' => $actual_url, 'actual_place' => $actual_place )); if ( $_POST['plus_code'] != $actual_place ) { $_SESSION['error'] = "Your plus_code did not match"; if ( $USER->instructor ) $_SESSION['error'] = "Your plus_code '".$_POST['plus_code']."' did not match $actual_place"; header('Location: '.addSession('index.php')); return; } $val = validate($sanity, $_POST['code']); if ( is_string($val) ) { $_SESSION['error'] = $val; header('Location: '.addSession('index.php')); return; } LTIX::gradeSendDueDate(1.0, $oldgrade, $dueDate); // Redirect to ourself header('Location: '.addSession('index.php')); return; } // echo($goodsha); if ( $RESULT->grade > 0 ) { echo('

Your current grade on this assignment is: '.($RESULT->grade*100.0).'%

'."\n"); } if ( $dueDate->message ) { echo('

'.$dueDate->message.'

'."\n"); } ?>

Calling a JSON API

In this assignment you will write a Python program somewhat similar to http://www.py4e.com/code3/opengeo.py. The program will prompt for a location, contact a web service and retrieve JSON for the web service and parse that data, and retrieve the first plus_code from the JSON. An Open Location Code is a textual identifier that is another form of address based on the location of the address.

API End Points

To complete this assignment, you should use this API endpoint that has a static subset of the Open Street Map Data.

?
This API also has no rate limit so you can test as often as you like. If you visit the URL with no parameters, you get "No address..." response.

To call the API, you need to provide the address that you are requesting as the q= parameter that is properly URL encoded using the urllib.parse.urlencode() function as shown in http://www.py4e.com/code3/opengeo.py

Test Data / Sample Execution

You can test to see if your program is working with a location of "" which will have a plus_code of "".

$ python solution.py
Enter location: 
Retrieving http://...
Retrieved  characters
Plus code 

Turn In

Please run your program to find the plus_code for this location:


Make sure to enter the name and case exactly as above and enter the plus_code and your Python code below. Hint: The first five characters of the plus_code are " ..."

Make sure to retreive the data from the URL specified above and not the normal Google API. Your program should work with the Google API - but the plus_code may not match for this assignment.

plus_code:
Python code:

X Tutup