Package: commute
This is a helper script for multi-modal commute planning based on the
information that you specify.commute.py helps users who travel across multiple modes of transportand multiple waypoints to make data-based decisions about which routeto use and prefer at a given time or at a given time in future.Table of contentsSample UsageInstallationConfigurationGet the Google API keyCreate the configuration fileSample configurationParts of the configuration
fileapi_keyplacesmapUsageStatusSample Usage$commute-cconfig.yml-sHOME-dWORKTotaltime:26min.Home(time:26m.w/trafficdrive)Work-----Totaltime:43min.Home(time:41m.waiting:02min.bus)Work-----Totaltime:45min.Home(time:25m.w/trafficdrive)Kwik-e-Mart(time:20m.w/trafficdrive)Work-----....InstallationYou can easily install this script using eitherpiporeasy_install$pipinstallcommuteor$easy_installcommuteConfigurationGet the Google API keyThis information is borrowed fromGoogle Maps Python client
repoEach Google Maps Web Service requires an API key or Client ID. API
keys arefreely available with a Google Account athttps://developers.google.com/console.To generate a server key for your project:Visithttps://developers.google.com/consoleand log in with
a Google Account.Select an existing project, or create a new project.ClickEnable an API.Browse for the API, and set its status to “On”. The Python Client for
Google Maps Services
accesses the following APIs:Directions APIDistance Matrix APIElevation APIGeocoding APITime Zone APIRoads APIOnce you’ve enabled the APIs, clickCredentialsfrom the left
navigation of the Developer
Console.In the “Public API access”, clickCreate new Key.ChooseServer Key.If you’d like to restrict requests to a specific IP address, do so
now.ClickCreate.Your API key should be 40 characters long, and begin withAIza.Create the configuration fileThen you will need to create aconfig.ymlfile, or just anyyamlfile with the following key fieldsapi_key:# your Google API key over hereplaces:# all the places which need to be trackedmap:# the map, or essentially how you commute between any two placesSample configurationapi_key:AIzaaaaaaaaaaaaaaaaaaaaaaaaaaaplaces:HOME:location:742, Evergreen Terrace, Springfieldalias:HomeWORK:location:Springfield Nuclear Power Plant, Springfieldalias:WorkKWIK_E_MART:location:Kwik-e-Mart, Springfieldalias:Apu'sMOES_TAVERN:location:Moe's Tavern, Springfieldalias:Moe'smap:HOME:KWIK_E_MART:-mode:drivingMOES_TAVERN:-mode:driving-mode:walkingWORK:-mode:driving-mode:transittransit_mode:busKWIK_E_MART:HOME:-mode:drivingMOES_TAVERN:-mode:driving-mode:walkingWORK:-mode:drivingMOES_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'sWORK:MOES_TAVERN:-mode:drivingParts of the configuration fileapi_keyapi_keywill hold the information about the Google Developer’s API
key.placesplacesholds information about all the places to be taken underconsideration, and a small description about their physical addressadd how to refer to them in the outputEach place has two attributes- location: the physical location of the place (the thing you type
into Google Maps).- alias: an alias to refer by and to use while printing the output.mapmapkey contains all the connections between the places, possibleways to travel between the places and multiple ways, if anyIt can also contain other detailed information about the specific way
of travel.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 destinationmap:PLACE1:PLACE2:-mode:driving-mode:transit............The routing information supports all the arguments that the Google Maps
python client takes. For more information refer toGoogle Maps Python
API
documentationUsage$commute-cconfig.yml-sHOME-dWORK$commute-cconfig.yml-sHOME-dWORK-wnow$commute-cconfig.yml-sHOME-dWORK-w'in an hour'$commute-cconfig.yml-sHOME-dWORK-w'friday evening @ 7'The date/time parsing is done with the help ofparsedatetimelibrary, so
look at thedocumentation to find more about the formats supported.For using it as a library,importtimefromcommuteimportget_all_paths,format_pathconfig_file="/path/to/config/file"src="HOME"dst="WORK"when=time.time()forrank,pathinget_all_paths(config,src,dst,when):print(format_path(rank,path))print("-"*5)StatusThis project is at a very early stage right now. Please try it out and
report any issues.