Code Monkey home page Code Monkey logo

wazeroutecalculator's Introduction

WazeRouteCalculator

Build Status

Calculate actual route time and distance with Waze API.

Installation

pip install WazeRouteCalculator

Tested on Python 2.7 and 3.6, 3.8, 3.10

Example

import WazeRouteCalculator

logger = logging.getLogger('WazeRouteCalculator.WazeRouteCalculator')
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler()
logger.addHandler(handler)

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. The address can also be coordinates. region is optional, and defaults to "EU". region can be one of:

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

Region is used for address searching. Setting base coord parameter. (Removed from route server selection. Looping through all route servers.)

Vehicle types

vehicle_type is also optional, and defaults to "" which is private. vehicle_type can be one of:

  • TAXI
  • MOTORCYCLE

Time to destination will be adjusted based on the mode of transport.

import WazeRouteCalculator

logger = logging.getLogger('WazeRouteCalculator.WazeRouteCalculator')
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler()
logger.addHandler(handler)

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

Avoid toll roads

avoid_toll_roads is also optional, and defaults to False. Setting avoid_toll_roads to True will only return results not on a tollway.

import WazeRouteCalculator

logger = logging.getLogger('WazeRouteCalculator.WazeRouteCalculator')
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler()
logger.addHandler(handler)

from_address = 'Chicago, Illinois'
to_address = 'New York City, New York'
region = 'US'
route = WazeRouteCalculator.WazeRouteCalculator(from_address, to_address, region, avoid_toll_roads=True)
route.calc_route_info()

Avoid subscription roads (vignette system)

avoid_subscription_roads is also optional, and defaults to False. Setting avoid_subscription_roads to True will only return results not involving a subscription road (toll roads in coutries that use vignettes).

import WazeRouteCalculator

logger = logging.getLogger('WazeRouteCalculator.WazeRouteCalculator')
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler()
logger.addHandler(handler)

from_address = 'Long Branch, New Jersey'
to_address = 'New York City, New York'
region = 'US'
route = WazeRouteCalculator.WazeRouteCalculator(from_address, to_address, region, avoid_subscription_roads=True)
route.calc_route_info()

Avoid ferries

avoid_ferries is also optional, and defaults to False. Setting avoid_ferries to True will only return results not involving a ferry.

import WazeRouteCalculator

logger = logging.getLogger('WazeRouteCalculator.WazeRouteCalculator')
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler()
logger.addHandler(handler)

from_address = 'Long Branch, New Jersey'
to_address = 'New York City, New York'
region = 'US'
route = WazeRouteCalculator.WazeRouteCalculator(from_address, to_address, region, avoid_ferries=True)
route.calc_route_info()

Multiple routes

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

import WazeRouteCalculator

logger = logging.getLogger('WazeRouteCalculator.WazeRouteCalculator')
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler()
logger.addHandler(handler)

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: Győr, Hungary
Start coords: (47.467660814, 19.077617881)
End coords: (47.67936706542969, 17.707035064697266)
Min	Max
72.92	80.33 minutes
118.75	120.21 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: {'routeType-shortRouteName': (route_time1, route_distance1), 'routeType-shortRouteName': (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

logger = logging.getLogger('WazeRouteCalculator.WazeRouteCalculator')
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler()
logger.addHandler(handler)

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.

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

Leave at

You can pass time_delta=<int> to calc_route_info or calc_all_routes_info to set the leave time from now. The value (minute) can be negative so you can step back and forward. Default 0 = now. The following example shows route info from now + 60 minute.

import WazeRouteCalculator

logger = logging.getLogger('WazeRouteCalculator.WazeRouteCalculator')
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler()
logger.addHandler(handler)

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(time_delta=60)
Time 73.33 minutes, distance 120.92 km.

No logging

log_lvl argument is depricated.

import WazeRouteCalculator

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

wazeroutecalculator's People

Contributors

bjohnson8949 avatar cbrherms avatar gkhartman avatar hmmbob avatar jorp avatar kovacsbalu avatar lcieslak avatar lovato avatar petro31 avatar regevbr avatar scimonster avatar sretalla avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wazeroutecalculator's Issues

Documentation

What source did you build this off of? I'm trying to make something similar and can't find anything on Waze's website.

ImportError: No module named requests

When I try to execute in a Mac OS i get this error

File "example.py", line 3, in <module>
    import WazeRouteCalculator
  File "/Users/***/WazeRouteCalculator/WazeRouteCalculator/__init__.py", line 2, in <module>
    from .WazeRouteCalculator import *
  File "/Users/***/WazeRouteCalculator/WazeRouteCalculator/WazeRouteCalculator.py", line 5, in <module>
    import requests
ImportError: No module named requests

I've tried of installing pip install request, but not working

Waypoint ?

Is it possible to request routing with waypoint ?
Does waze API support this ?

Internal Error

i tried to run the sample python i get the same error, can you confirm that maybe something has changed in the api?

From: Budapest, Hungary - to: Győr, Hungary
Start coords: (47.467660814, 19.077617881)
End coords: (47.67936706542969, 17.707035064697266)
Internal Error

Miles

Hello,
Is is possible to get results in miles instead of km ?

Add support to calculate routes with addresses in Brazil

Although it is possible to calculate distances using lat/long in Brazil with region AU, it is not possible to convert address to lat/long from AU region, without country information. Looks like issue is related to base coordinates. I have added BR with base coordinates and it works accordingly.

import WazeRouteCalculator
import logging

logger = logging.getLogger('WazeRouteCalculator.WazeRouteCalculator')
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler()
logger.addHandler(handler)

# from_address = '-22.609454573, -43.179068844'
# to_address = '-22.902955752, -43.185864835'
from_address = 'rua sete de setembro,rio de janeiro'
to_address = 'avenida presidente vargas, rio de janeiro'
region = 'BR'
route = WazeRouteCalculator.WazeRouteCalculator(from_address, to_address, region)
route.calc_route_info()

Output

From: rua sete de setembro,rio de janeiro - to: avenida presidente vargas, rio de janeiro
Start coords: (-22.609454573, -43.179068844)
End coords: (-22.902955752, -43.185864835)
Time 53.87 minutes, distance 51.97 km.

Changing region to AU coordinates would be wrong

region = 'AU'

Output

From: rua sete de setembro,rio de janeiro - to: avenida presidente vargas, rio de janeiro
Start coords: (-34.84001541137695, 150.593994140625)
End coords: (-26.43230438232422, 133.2591094970703)
Time 1555.48 minutes, distance 2354.24 km.

I have submitted a pull request with this support to Brazil. #56 Add support to region BR

Update needed

An error appear a few days ago.

While doing calc_route_info() , I receive an error:

File "/usr/local/lib/python2.7/dist-packages/WazeRouteCalculator/WazeRouteCalc ulator.py", line 79, in calc_route_info route = self.get_route() File "/usr/local/lib/python2.7/dist-packages/WazeRouteCalculator/WazeRouteCalc ulator.py", line 69, in get_route response_json = json.loads(response) File "/usr/lib/python2.7/json/__init__.py", line 326, in loads return _default_decoder.decode(s) File "/usr/lib/python2.7/json/decoder.py", line 365, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python2.7/json/decoder.py", line 383, in raw_decode raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded

I suppose Waze did an update...

Issue with coordinates in australia

I have an issue with australian travel times
i have the riegon as 'AU' so that may be the issue

Output
From: 1 Marita Road, Perth, WA - to: 1 North Street, Perth, WA Start coords: (-34.4881591796875, 150.90646362304688) End coords: (-31.931893945, 115.85721939) Time 2661.83 minutes, distance 4010.51 km.
this is incorrect because 1 northstreet is like 1KM from Marita Road so it makes no sense

Output
From: 1 Marita Road, Perth, WA - to: 5 Davies Road, Perth, WA Start coords: (-34.4881591796875, 150.90646362304688) End coords: (-34.4881591796875, 150.90646362304688) Time 0.23 minutes, distance 0.04 km.
this is actually correct,

Output
From: 182 Little Marine Parade, Perth, WA - to: 5 Davies Road, Perth, WA Start coords: (-27.988226795, 153.429991207) End coords: (-34.4881591796875, 150.90646362304688) Time 581.32 minutes, distance 952.95 km.

but this is also incorrect, as these places are also 5KM from each other, so i dont think the start coords are correct, cos 153 isnt the y coord of 182 Little Marine Parade.

how do i fix this issue, it seems like it is just getting the wrong place, is there anyway to ensure that this doesnt happen?
specifying the suburb ect. could potentially be done, but the suburbs are just randomly assigned in my data, with many of them just being 'suburb1', so if there are any other suggestions that would be easier as i have hundreds of addresses in my db.

Included regions

Why are the only regions included for traffic and routing optimization Europe, North America and Israel?
Would be great to see other territories approached as well, such as Brazil or South America.

Europe address_to_coords issue

Hi,
it seems to me that the 'address_to_coords' returns incorrect coordinates (I used Italian addresses). I think it depends on the 'EU' COORD_SERVERS: if I use 'SearchServer/mozi' instead of 'row-SearchServer/mozi' it seems to work correctly.
Let me know if you agree.

Thank you very much,
Eleonora

Vignette system not processed in EU (rp_subscription)

The changes on the waze site means that when routing in Europe, unless Vignettes are specified to cover toll roads, toll roads will not be used in the route regardless of the avoid_toll_roads selection.

In order to get it to work properly, you can either set preferences in the mobile app to indicate you have the vignette for the country(ies), or you can add &rp_subscription=* to the URL (or specify the country if you only have a vignette in one country), which works to see toll roads in the calculation.

What I can't work out is how to adjust the script to allow for this... I tried adding it in the url_options section, but no success there... please help as the route calculation is always using a longer route and hence useless.

Enhancement: Unit conversion for time and distance

It would be great if there was a way to specify distance and time units by passing in new parameters to calc_route_info and calc_all_route_info. I was thinking of using pint to handle the unit conversions. I have an idea of how to implement this, just wanted to get your thoughts and see if it was worth the effort. The plan would be to add additional parameters to both functions but to keep the default values such that the expected output doesn't change.

Let me know what you think!

Europe address_to_coords issue #38 is happening again

Europe address_to_coords issue #38 is currently happening

From: 19 Albyn Drive, Livingston, UK - to: 2 Station Road, Prestonpans, UK
Start coords: (55.88032913208008, -3.524367570877075)
End coords: (52.34578323364258, 1.5044173002243042)
Time 446.55 - 493.93 minutes, distance 720.30 - 766.54 km.

Which is very much not correct. Grabbing some debug on the returned json
{'bounds': None, 'businessName': 'Starbucks Drive Through', 'city': 'Livingston', 'countryName': 'United Kingdom', 'location': {'lat': 55.88032913208008, 'lon': -3.524367570877075}, 'name': 'Starbucks Drive Through', 'number': None, 'provider': 'waze', 'segmentId': -1, 'state': 'West Lothian', 'stateName': 'No State', 'street': None, 'streetId': 0}

{'bounds': None, 'businessName': 'Station Road', 'city': 'Halesworth', 'countryName': 'United Kingdom', 'location': {'lat': 52.34578323364258, 'lon': 1.5044173002243042}, 'name': 'Station Road', 'number': None, 'provider': 'waze', 'segmentId': -1, 'state': 'Suffolk', 'stateName': 'No State', 'street': None, 'streetId': 0}

so it has found a Station Road in Halesworth not Prestonpans.

Modifying the COORD_SERVERS for EU to be SearchServer/mozi as per issue #38 the returned jsons become
{'bounds': {'bottom': 55.86370668029149, 'left': -3.518317480291502, 'right': -3.515619519708498, 'top': 55.8610087197085}, 'businessName': None, 'city': 'Murieston', 'countryName': 'United Kingdom', 'location': {'lat': 55.86235809326172, 'lon': -3.5169684886932373}, 'name': '19 Albyn Dr, Murieston, Livingston EH54 9JN', 'number': '19', 'provider': 'waze', 'segmentId': -1, 'state': 'Scotland', 'stateName': 'No State', 'street': 'Albyn Drive', 'streetId': 0}

{'bounds': {'bottom': 55.9558145802915, 'left': -2.979162080291502, 'right': -2.976464119708498, 'top': 55.9531166197085}, 'businessName': None, 'city': 'Prestonpans', 'countryName': 'United Kingdom', 'location': {'lat': 55.954463958740234, 'lon': -2.9778130054473877}, 'name': '2 Station Rd, Prestonpans EH32 9EP', 'number': '2', 'provider': 'waze', 'segmentId': -1, 'state': 'Scotland', 'stateName': 'No State', 'street': 'Station Road', 'streetId': 0}

Which is much better :)

Waze integration errors when 'overseas', prefer simple warnings or no errors

The problem

I have a integration between a device (phone) and home location, thus indicating the amount of time from home.
This works fine but not when the device is on an island, i.e. the example I have is when the device is on Corsica and the home address is on France mainland. Now, I am OK that this does not work but it should not throw unnecessary errors.

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 514, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 709, in async_device_update
    raise exc
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/waze_travel_time/sensor.py", line 169, in update
    self._waze_data.update()
  File "/usr/src/homeassistant/homeassistant/components/waze_travel_time/sensor.py", line 216, in update
    routes = params.calc_all_routes_info(real_time=realtime)
  File "/usr/local/lib/python3.10/site-packages/WazeRouteCalculator/WazeRouteCalculator.py", line 209, in calc_all_routes_info
    results = {"%s-%s" % (route['routeType'][0], route['shortRouteName']): self._add_up_route(route['results' if 'results' in route else 'result'], real_time=real_time, stop_at_bounds=stop_at_bounds) for route in routes}
  File "/usr/local/lib/python3.10/site-packages/WazeRouteCalculator/WazeRouteCalculator.py", line 209, in <dictcomp>
    results = {"%s-%s" % (route['routeType'][0], route['shortRouteName']): self._add_up_route(route['results' if 'results' in route else 'result'], real_time=real_time, stop_at_bounds=stop_at_bounds) for route in routes}
IndexError: list index out of range

What version of Home Assistant Core has the issue?

2022.8.4 (1 as well)

What was the last working version of Home Assistant Core?

none

What type of installation are you running?

Home Assistant Container

Integration causing the issue

waze

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

calc_all_routes_info always return dict with 1 value.

I'm trying to get info about possible routes between two points

from WazeRouteCalculator import WazeRouteCalculator
from_address = 'Budapest, Hungary'
to_address = 'Győr, Hungary'
wrc = WazeRouteCalculator(from_address, to_address)
routes = wrc.calc_all_routes_info()
print(len(routes))

I played with different addresses and input params, but routes as result of calc_all_routes_info always has just one element, while I expected several (according to README.md)

I dig into source of of the method and found following
Lines 208-209 in WazeRouteCalculator

routes = self.get_route(npaths, time_delta)
results = {route['routeName' if 'routeName' in route else 'route_name']: self._add_up_route(route['results' if 'results' in route else 'result'], real_time=real_time, stop_at_bounds=stop_at_bounds) for route in routes}

On line 208 variable routes as result of the API call has 2 values (as expected) but on the line 209 results has only one value, which is returned afterwards.

I'm not good in python, so I cannot understand the logic of the results calculation, but it looks strange.

Is is an expected behavior?

Thanks in advance, for your clarification

HA reports an error in WazeRouteCalculator

Hey,
I'm using the waze component in Home Assistant that uses this package.
The component reports the following:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/waze_travel_time/sensor.py", line 238, in first_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/waze_travel_time/sensor.py", line 264, in update
    self._waze_data.update()
  File "/usr/src/homeassistant/homeassistant/components/waze_travel_time/sensor.py", line 320, in update
    routes = params.calc_all_routes_info(real_time=realtime)
  File "/usr/local/lib/python3.9/site-packages/WazeRouteCalculator/WazeRouteCalculator.py", line 203, in calc_all_routes_info
    results = {route['routeName']: self._add_up_route(route['results'], real_time=real_time, stop_at_bounds=stop_at_bounds) for route in routes}
  File "/usr/local/lib/python3.9/site-packages/WazeRouteCalculator/WazeRouteCalculator.py", line 203, in <dictcomp>
    results = {route['routeName']: self._add_up_route(route['results'], real_time=real_time, stop_at_bounds=stop_at_bounds) for route in routes}
TypeError: list indices must be integers or slices, not str

Is it coming from your side?
cheers.

empty vehicleType causes empty response.

"vehicleType": self.vehicle_type,

^ This being empty when vehicle_type is not defined causes an empty response. If it is included in the sent params it must contain a valid type of 'PRIVATE', 'TAXI', 'MOTORCYCLE', or 'ELECTRIC' (US and Canada region only).
source

cbherms@Herms-PC:/mnt/d/Documents/GitHub/WazeRouteCalculator$ python example.py
From: Budapest, Hungary - to: Győr, Hungary
empty response

Admittedly I was unaware private and electric were accepted values, hence setting it to taxi, though i now also realise using taxi instead of private would skew routes as they can use bus lanes in some countries.

Either way, setting it to 'PRIVATE' if it is undefined will fix the above issue, unless you wish to have a check to see if the variable contains anything.
Also, including the full list of options including the note for Electric would be useful to others.

Waze travel time in Slovakia (and other EU countries) not using highways

Hello since the addition of vignettes for highways in 12.12. 2018 (I read this on waze forum). The route calculations for Slovakia (maybe other countries aswell) does not seem to be working properly. As I recall the waze travel time component uses waze's live map to calculate the best route. However for Slovakia it does not as you can see below. (No this has nothing to do with obstructions on the highway because the mobile app reports it correctly.)

Another guy already pointed to this in this issue of home assistant:
Issue #25964

This route should take no more than 90 minutes.
image

My question is is it possible to manually implement or push or maybe even tick boxes for highway vignettes (passes) so it can calculate the routes correctly ? Or is it possible to take the updated map (as a pointer of some sort) for slovakian region so it uses the correct one?

Here you can see the original live map which to this date has not been fixed to use highways. It seems like the developers missed inplementing highway permissions for Slovakian map.
image

However, some slovakian developers from wazer.sk optimized the code and implemented the highway vignettes so it calculates correctly now.
image

here is the link to the updated map:
Updated routing map

UPDATE: I was in contact with the guys who did this and they just said it only uses a paramater (in the link I think) that ignores restrictions such as highway vignettes (for Slovakia).

Request: Australia region

Hi,

Thanks for your work on this.

I was wondering if it would be possible for you to add Australia as a region in WazeRouteCalculator?

Thanks,

Calculate a time and distance matrix from WazeRouteCalculator

Hello,
As I understand right now, the route is calculated from the date you send the request and the time_delta is only minutes you add to your current time.

Is there a way to calculate for example from 6:00 am to 8 pm the averages time and distance for each 10 minutes intervals on one day ?

Thanks for answering,

LGPL-3 or GPL-3

Hi Kovács,

Thanks for your work.

I am using your component WazeRouteCalculator for my Home Assistant Overlay for Gentoo Linux and I am confused about your license selection.

You state LGPL-3 on Github Project Page, and GPL-3 in setup-py and on Pypi. These are different but should be unique.

I have now assumed that GPL-3is the correct License for your package, 3 against 1, just wanted to ask for clarification.

You can find your component at my Overlay at: https://github.com/onkelbeh/HomeAssistantRepository/tree/master/dev-python/WazeRouteCalculator.

Please drop me a note if you find something wrong.

\B.

ValueError: Unknown level:

When running:

import WazeRouteCalculator

from_address = 'Budapest, Hungary'
to_address = 'Gyor, Hungary'
region = 'EU'

route = WazeRouteCalculator.WazeRouteCalculator(from_address, to_address, region)

The last line gives ValueError: Unknown level: 'EU'

Release latest 3 commits since 0.15

Hi @kovacsbalu , I just saw that the Homeassistant Integration using this lib shows the following error:

File "/usr/local/lib/python3.10/site-packages/WazeRouteCalculator/WazeRouteCalculator.py", line 209, in calc_all_routes_info
    results = {"%s-%s" % (route['routeType'][0], route['shortRouteName']): self._add_up_route(route['results' if 'results' in route else 'result'], real_time=real_time, stop_at_bounds=stop_at_bounds) for route in routes}
IndexError: list index out of range

Before digging deeper I would like to use your latest changes which might fix this issue.

Could you please create a new release?
Thank you

does this always return km?

Seems to sometimes return imperial units depending on location. Are there any docs for this api endpoint?

Toll roads avoided in some countries when avoid_toll_roads not set.

In some European countries (and maybe others), the vignette system is used for toll roads and the Waze API doesn't respect them as toll roads, rather as subscription roads, meaning without setting the avoid_toll_roads option to True, toll roads are avoided in those countries regardless.

A new option for subscription roads is needed.

Calling calc_route_info() results in JSONDecodeError

Update: When looking deeper I noticed that the request in get_routes() returns a 403 error response.

Here's the error message at the bottom of the resulting stack trace:

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

This code should reproduce the error (confirmed on python 2.7):

import WazeRouteCalculator


from_address = 'Los Angeles, CA'
to_address = 'San Fransisco, CA'
region = 'US'
route = WazeRouteCalculator.WazeRouteCalculator(from_address, to_address, region)
print route.calc_route_info()

Duplicate logging in HA

When using WazeRouteCalculator in HomeAssistant (and presumably elsewhere), certain lines are logged multiple times. For example:

From: 31.AAAA,34.BBBB - to: 31.CCCC,34.DDDD
2019-10-07 17:31:33 INFO (SyncWorker_7) [WazeRouteCalculator.WazeRouteCalculator] From: 31.AAAA,34.BBBB - to: 31.CCCC,34.DDDD
Start coords: (31.AAAA, 34.BBBB)
End coords: (31.CCCC, 34.DDDD)
Time 0.25 - 0.25 minutes, distance 0.04 - 0.04 km.
2019-10-07 17:31:33 INFO (SyncWorker_7) [WazeRouteCalculator.WazeRouteCalculator] Time 0.25 - 0.25 minutes, distance 0.04 - 0.04 km.

This seems to be because of:

        if not len(self.log.handlers):
            self.log.addHandler(logging.StreamHandler())

Is there a reason why you do this?

Internal Error

Hey,

Thank you very much for your awesome algorithm. I'm getting Internal Error randomly after running the script (sometimes among "empty responses") Do you know why and how could I avoid it?

Thank you very much in advance.

Thomas

log_lvl

Hi,

I have the following warning in my home assistant log:

WARNING (SyncWorker_9) [WazeRouteCalculator.WazeRouteCalculator] log_lvl is deprecated please check example.py

ValueError

Hey,

Thanks a lot for the API, been using it off and on for a while. Wanted to use it this week and saw this error trace getting thrown with the simple scripts I've written. (Tbh it's your quickstart script with changed hardcoded locations nothing big really)
And I've been getting this:

PS C:\Users\X\Github\WazeRouteCalculator> python .\NamurHome.py
From: Namur - to: Lokeren, België
Traceback (most recent call last):
  File ".\NamurHome.py", line 9, in <module>
    route.calc_route_info()
  File "C:\Users\X\Github\WazeRouteCalculator\WazeRouteCalculator\WazeRouteCalculator.py", line 133, in calc_route_info
    route = self.get_route(1, time_delta)
  File "C:\Users\X\Github\WazeRouteCalculator\WazeRouteCalculator\WazeRouteCalculator.py", line 92, in get_route
    response_json = response.json()
  File "C:\Python34\lib\site-packages\requests\models.py", line 892, in json
    return complexjson.loads(self.text, **kwargs)
  File "C:\Python34\lib\json\__init__.py", line 318, in loads
    return _default_decoder.decode(s)
  File "C:\Python34\lib\json\decoder.py", line 343, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python34\lib\json\decoder.py", line 361, in raw_decode
    raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0)

Am I missing something obvious here?

Kind Regards,

Can we have a release with the latest changes please?

Commit a502c65 fixes some issues introduced by Waze API changes. For example, Home Assistant Waze integration is currently broken (home-assistant/core#61251) because HA uses WazeRouteCalculator==0.13 as a dependency.

Could you please release a new version of this awesome library with the latest changes included so HA bug can be fixed without hacks like manual replacement of WazeRouteCalculator?

Latest code works perfectly and needs no changes - only a new release is needed.

using behind proxy

I want to use wazeroutecalculator but i want to specify a proxy to use in the request made by the lib. How can i do that.

Json error accepted while testing simple example

on python 2.7 while running the example, receive an abend as attached:
(worked fine couple of months ago...)

From: Budapest, Hungary - to: Gyor, Hungary
Traceback (most recent call last):
File "work.py", line 9, in
route.calc_route_info()
File "/usr/local/lib/python2.7/dist-packages/WazeRouteCalculator/WazeRouteCalculator.py", line 133, in calc_route_info
route = self.get_route(1, time_delta)
File "/usr/local/lib/python2.7/dist-packages/WazeRouteCalculator/WazeRouteCalculator.py", line 92, in get_route
response_json = response.json()
File "/usr/lib/python2.7/dist-packages/requests/models.py", line 850, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python2.7/dist-packages/simplejson/init.py", line 516, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line 374, in decode
obj, end = self.raw_decode(s)
File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line 404, in raw_decode
return self.scan_once(s, idx=_w(s, idx).end())
simplejson.scanner.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Error not properly raised

Empty response is always raised in get_route when no servers return a result because if statement has an extra not. Should be:

if response_json and 'error' in response_json:

I'd also argue that the error "empty response" should be changed to "no response from server"

Lastly, Why do these errors occur so much? I added a debug statement in the loop to see responses and it seems like the waze api is always returning an 'error': 'Internal Error'.

No JSON object could be decoded

Szia,
mostanában ezt a hibaüzenetet kapom:
File "wazetest.py", line 6, in
route.calc_route_info()
File "/usr/local/lib/python2.7/dist-packages/WazeRouteCalculator/WazeRouteCalculator.py", line 133, in calc_route_info
route = self.get_route(1, time_delta)
File "/usr/local/lib/python2.7/dist-packages/WazeRouteCalculator/WazeRouteCalculator.py", line 92, in get_route
response_json = response.json()
File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 892, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python2.7/json/init.py", line 338, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

nem tudod mi lehet a gond?

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.