Google Directions API, Part 2
=============================
Contents
--------
.. toctree::
:maxdepth: 1
Indices and tables
------------------
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
Exercise
--------
For this week, the goal is to implement a function that does the following:
* The function should accept 3 parameters, which you parsed with the argument parsing function last week:
* Starting location
* Destination location
* Trip waypoints: None or List
* Sends an http request to the `Google Directions API `_
* Full information on how to construct a link can be found at the API site (note: an API key is not actually required), but here are some guidelines:
* Use `http://maps.googleapis.com/maps/api/directions/json?` as the base of the query. Http works best for python and we want json output.
* Options are added as name=value, with & joining multiple options together. Start = "origin", End = "destination", Waypoints = "waypoints"
* `Here is a sample query to illistrate `_
* Return the json result.
This excercise will require use of the :py:mod:`requests` package, specifically :py:mod:`requests.get`
For exceptions look at :py:exc:`requests.ConnectionError` and :py:exc:`requests.Timeout`
Requests should be installed now, if not try
.. code-block:: bash
$ sudo -H pip3 install -U requests
On completion of this exercies, you should be able to run your stub program and have it do the following:
* Parse the arguments as outlined last week
* Print the query result with just a start and end point passed.
* Print the query result with start, end, and one or more waypoints passed.
Note: you might receive a response from the API about being over your allotted number of requests. If this happens, just try again.
Hints
-----
To help you get started, here is one possible signature for the request function:
.. literalinclude:: directions2.py
:language: python3
:lines: 60-67
* Use exception handling as appropriate.
Solution
--------
When you are ready to see one possible solution, try :download:`this file `