commute.py helps users who travel across multiple modes of transport and multiple waypoints to make data-based decisions about which route to use and prefer at a given time or at a given time in future.
This is a helper script for multi-modal commute planning based on the information that you specify.
$ commute -c config.yml -s HOME -d WORK Total time: 26min. Home (time: 26m. w/traffic drive) Work ----- Total time: 43min. Home (time: 41m. waiting: 02min. bus) Work ----- Total time: 45min. Home (time: 25m. w/traffic drive) Kwik-e-Mart (time: 20m. w/traffic drive) Work ----- ....
You can easily install this script using either pip or easy_install
$ pip install commute
$ easy_install commute
This information is borrowed from Google Maps Python client repo
Your API key should be 40 characters long, and begin with AIza.
Then you will need to create a config.yml file, or just any yaml file with the following key fields
api_key: # your Google API key over here places: # all the places which need to be tracked map: # the map, or essentially how you commute between any two places
api_key: AIzaaaaaaaaaaaaaaaaaaaaaaaaaaa places: HOME: location: 742, Evergreen Terrace, Springfield alias: Home WORK: location: Springfield Nuclear Power Plant, Springfield alias: Work KWIK_E_MART: location: Kwik-e-Mart, Springfield alias: Apu's MOES_TAVERN: location: Moe's Tavern, Springfield alias: Moe's map: HOME: KWIK_E_MART: - mode: driving MOES_TAVERN: - mode: driving - mode: walking WORK: - mode: driving - mode: transit transit_mode: bus KWIK_E_MART: HOME: - mode: driving MOES_TAVERN: - mode: driving - mode: walking WORK: - mode: driving MOES_TAVERN: HOME: - mode: driving # drinking and driving is not encouraged - mode: walking # You don't go to Kwik-e-mart or to work from Moe's WORK: MOES_TAVERN: - mode: driving
api_key will hold the information about the Google Developer’s API key.
The first nesting under map contains the source, use the identifier from the places key above.
map: PLACE1: PLACE2: .... .... ....
The next nesting contains a map of possible destinations from the source, which contains the possible ways to travel from the source to the destination
map: PLACE1: PLACE2: - mode: driving - mode: transit .... .... ....
The routing information supports all the arguments that the Google Maps python client takes. For more information refer to Google Maps Python API documentation
$ commute -c config.yml -s HOME -d WORK $ commute -c config.yml -s HOME -d WORK -w now $ commute -c config.yml -s HOME -d WORK -w 'in an hour' $ commute -c config.yml -s HOME -d WORK -w 'friday evening @ 7'
For using it as a library,
import time from commute import get_all_paths, format_path config_file = "/path/to/config/file" src = "HOME" dst = "WORK" when = time.time() for rank, path in get_all_paths(config, src, dst, when): print(format_path(rank, path)) print("-" * 5)
This project is at a very early stage right now. Please try it out and report any issues.