Google Directions API, Part 1¶
Contents¶
Indices and tables¶
Background¶
Instead of working on a small script for this exercise, you will create part of a larger application! Over a few weeks you will create an application that parses command line inputs, queries the Google Directions API, parses the response and prints some nicely formatted directions!
That’s a lot to do all at once, which is why you will work on individual parts. For this week, the focus is on parsing inputs.
Exercise¶
For this week, the goal is to create an argument parsing function that does the following:
It should accept two positional arguments as strings:
- Starting location
- Destination location
It should accept 3 optional arguments:
- An output file path (for now, don’t concern yourself with the contents of the file)
- An input file path (for now, don’t concern yourself with the contents of the file)
- One or more trip way-points.
It should be able to print it’s usage / help information to the terminal if called with
--help
argument present.It should be able to print it’s version information to the terminal if called with the
--version
argument present.
This will require using the argparse
package.
On completion of this exercise, you should be able to run your stub program and have it do the following:
- Accept the above described arguments from the command line
- Print out a listing of the argument names and active values to the terminal
- Print out a listing
- Terminate itself cleanly
Hints¶
To help you get started, here is the start of one implementation:
#!/usr/bin/env python3 """ This is an exercise to work with argparse, and create a function to parse arguments for our Google Directions query. We will be using the Google Directions API: (https://developers.google.com/maps/documentation/directions/) """ import argparse def parsing_example(): """
Use exception handling as appropriate.