Giter Site home page Giter Site logo

gkhartman / wazeroutecalculator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kovacsbalu/wazeroutecalculator

0.0 2.0 0.0 36 KB

Calculate actual route time and distance with Waze api

License: GNU Lesser General Public License v3.0

Python 100.00%

wazeroutecalculator's Introduction

WazeRouteCalculator

Build Status Coverage Status

Calculate actual route time and distance with Waze API.

Installation

pip install WazeRouteCalculator

Tested on Python 2 and 3.

Example

import WazeRouteCalculator

from_address = 'Budapest, Hungary'
to_address = 'Gyor, Hungary'
region = 'EU'
route = WazeRouteCalculator.WazeRouteCalculator(from_address, to_address, region)
route.calc_route_info()
python example.py
From: Budapest, Hungary - to: Gyor, Hungary
Time 69.27 minutes, distance 120.91 km.

calc_route_info returns a tuple (route_time, route_distance) in addition to logging.

from_address and to_address are required. region is optional, and defaults to "EU". region can be one of:

  • EU (Europe)
  • US or NA (North America)
  • IL (Israel)

The Waze API has separate URLs for each region, and so identifying the correct region is crucial.

Multiple routes

You can get multiple routes using the route.calc_all_routes_info() function:

import WazeRouteCalculator

from_address = 'Budapest, Hungary'
to_address = 'Gyor, Hungary'
region = 'EU'
route = WazeRouteCalculator.WazeRouteCalculator(from_address, to_address, region)
route.calc_all_routes_info()
python example.py
From: Budapest, Hungary - to: Gyor, Hungary
Time 74.45 - 129.43 minutes, distance 120.91 - 130.08 km.

calc_all_routes_info takes an optional single parameter, the number of routes to fetch. Note that the Waze API may not return as many possibilities as requested. The function returns a dict: {'route_name1': (route_time1, route_distance1), 'route_name2': (route_time2, route_distance2), ...}.

No real time

You can pass real_time=False to calc_route_info or calc_all_routes_info to get the time estimate not including current conditions, but rather the average travel time for the current time. This would avoid something like traffic accidents or construction that is slowing down traffic abnormally on the day you run it from messing up the data. Note that this is not the same as travel time with no traffic at all, it is simply the usual traffic.

Intercity travel times only

Sometimes you may want to map travel times between cities and just see how long it takes to get from one to other. However, Waze's API will take you between two specific spots in the city, which can add to the time and distance, especially in larger cities.

You can pass stop_at_bounds=True to calc_route_info or calc_all_routes_info and it will ignore travel within the origin and destination cities.

import WazeRouteCalculator

from_address = 'Budapest, Hungary'
to_address = 'Gyor, Hungary'
region = 'EU'
route = WazeRouteCalculator.WazeRouteCalculator(from_address, to_address, region)
From: Budapest, Hungary - to: Gyor, Hungary

route.calc_route_info(stop_at_bounds=True)
Time 46.27 minutes, distance 95.29 km.
(46.266666666666666, 95.294)

route.calc_route_info()
Time 72.42 minutes, distance 121.33 km.
(72.41666666666667, 121.325)

Silence logging

Pass log_lvl=None to silence output and just get the return value:

import WazeRouteCalculator

from_address = 'Budapest, Hungary'
to_address = 'Gyor, Hungary'
route = WazeRouteCalculator.WazeRouteCalculator(from_address, to_address, log_lvl=None)
route_time, route_distance = route.calc_route_info()
print 'Time %.2f minutes, distance %.2f km.' % (route_time, route_distance)

wazeroutecalculator's People

Contributors

kovacsbalu avatar scimonster avatar lovato avatar gkhartman avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.