GithubHelp home page GithubHelp logo

eifinger / pywaze Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 2.0 180 KB

Asynchronous Waze client for calculating routes and travel times.

License: MIT License

Python 100.00%
hacktoberfest python traffic waze

pywaze's Introduction

pywaze

Asynchronous Waze client for calculating routes and travel times.

Based on WazeRouteCalculator

Installation

pip install pywaze

Usage

#!/usr/bin/env python3

import asyncio
from pywaze import route_calculator


async def get_time(start: str, end: str) -> float:
    """Return the travel time home."""

    async with route_calculator.WazeRouteCalculator() as client:
        results = await client.calc_all_routes_info(start, end)
        route_time, _ = list(results.values())[0]
        return route_time


start = "50.00332659227126,8.262322651915843"
end = "50.08414976707619,8.247836017342934"

travel_time = asyncio.run(get_time(start, end))

print(travel_time)

pywaze's People

Contributors

dependabot[bot] avatar eifinger avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

sisalik

pywaze's Issues

Internal Error When Trying to Get Travel Times

I am attempting to get travel times between two locations in the northeaster US and am receiving the following error:

Traceback (most recent call last):
  File "c:\Users\clayt\OneDrive\Documents\Waze Travel Time\waze_get_travel_time_2.py", line 19, in <module>
    travel_time = asyncio.run(get_time(start, end))
  File "C:\Program Files\Python310\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Program Files\Python310\lib\asyncio\base_events.py", line 646, in run_until_complete
    return future.result()
  File "c:\Users\clayt\OneDrive\Documents\Waze Travel Time\waze_get_travel_time_2.py", line 11, in get_time
    results = await client.calc_all_routes_info(start, end)
  File "C:\Users\clayt\OneDrive\Documents\Waze Travel Time\env\lib\site-packages\pywaze\route_calculator.py", line 289, in calc_all_routes_info
    routes = await self.get_route(
  File "C:\Users\clayt\OneDrive\Documents\Waze Travel Time\env\lib\site-packages\pywaze\route_calculator.py", line 172, in get_route
    raise WRCError(response_json.get("error"))
pywaze.route_calculator.WRCError: Internal Error

My code is included below:

#!/usr/bin/env python3

import asyncio
from pywaze import route_calculator


async def get_time(start: str, end: str) -> float:
    """Return the travel time home."""

    async with route_calculator.WazeRouteCalculator() as client:
        results = await client.calc_all_routes_info(start, end)
        route_time, _ = list(results.values())[0]
        return route_time


start = "39.98025243,-74.1783464"
end = "40.8765308,-73.41253281"

travel_time = asyncio.run(get_time(start, end))

print(travel_time)

Note that I am able to successfully get a travel time using the "WazeRouteCalculator" repository from here:

https://github.com/kovacsbalu/WazeRouteCalculator

Lots of ReadTimeout errors

Hello,

I'm running on Home Assistant 2023.9.0b3 and I have 6 Waze sensors.

With pywaze, I get lots of stack traces, more than with the previous module. Lots of ReadTimeout during all the day.
When latest restart HA, I have 5 failures but 1 that succeeds to update, don't know if it can be related to throttling per IP.

Also, do you know how to hide them? It does not work with:

logger:
  default: error
  logs:
    homeassistant.components.waze_travel_time: fatal

Stack trace:

2023-09-04 22:09:07.227 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.retour_maison_morgane fails
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/anyio/streams/tls.py", line 131, in _call_sslobject_method
result = func(*args)
^^^^^^^^^^^
File "/usr/local/lib/python3.11/ssl.py", line 921, in read
v = self._sslobj.read(len)
^^^^^^^^^^^^^^^^^^^^^^
ssl.SSLWantReadError: The operation did not complete (read) (_ssl.c:2580)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/httpcore/_backends/anyio.py", line 34, in read
return await self._stream.receive(max_bytes=max_bytes)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/anyio/streams/tls.py", line 196, in receive
data = await self._call_sslobject_method(self._ssl_object.read, max_bytes)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/anyio/streams/tls.py", line 138, in _call_sslobject_method
data = await self.transport_stream.receive()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 1203, in receive
await self._protocol.read_event.wait()
File "/usr/local/lib/python3.11/asyncio/locks.py", line 213, in wait
await fut
asyncio.exceptions.CancelledError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/httpcore/_exceptions.py", line 10, in map_exceptions
yield
File "/usr/local/lib/python3.11/site-packages/httpcore/_backends/anyio.py", line 32, in read
with anyio.fail_after(timeout):
File "/usr/local/lib/python3.11/site-packages/anyio/_core/_tasks.py", line 119, in __exit__
raise TimeoutError
TimeoutError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
yield
File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
resp = await self._pool.handle_async_request(req)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/httpcore/_async/connection_pool.py", line 262, in handle_async_request
raise exc
File "/usr/local/lib/python3.11/site-packages/httpcore/_async/connection_pool.py", line 245, in handle_async_request
response = await connection.handle_async_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/httpcore/_async/connection.py", line 96, in handle_async_request
return await self._connection.handle_async_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/httpcore/_async/http11.py", line 121, in handle_async_request
raise exc
File "/usr/local/lib/python3.11/site-packages/httpcore/_async/http11.py", line 99, in handle_async_request
) = await self._receive_response_headers(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/httpcore/_async/http11.py", line 164, in _receive_response_headers
event = await self._receive_event(timeout=timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/httpcore/_async/http11.py", line 200, in _receive_event
data = await self._network_stream.read(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/httpcore/_backends/anyio.py", line 31, in read
with map_exceptions(exc_map):
File "/usr/local/lib/python3.11/contextlib.py", line 155, in __exit__
self.gen.throw(typ, value, traceback)
File "/usr/local/lib/python3.11/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions
raise to_exc(exc) from exc
httpcore.ReadTimeout
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 679, in async_update_ha_state
await self.async_device_update()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 924, in async_device_update
await self.async_update()
File "/usr/src/homeassistant/homeassistant/components/waze_travel_time/sensor.py", line 146, in async_update
await self._waze_data.async_update()
File "/usr/src/homeassistant/homeassistant/components/waze_travel_time/sensor.py", line 187, in async_update
routes = await self.client.calc_all_routes_info(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/pywaze/route_calculator.py", line 271, in calc_all_routes_info
routes = await self.get_route(
^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/pywaze/route_calculator.py", line 148, in get_route
response: httpx.Response = await self.client.get(
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1757, in get
return await self.request(
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1530, in request
return await self.send(request, auth=auth, follow_redirects=follow_redirects)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1617, in send
response = await self._send_handling_auth(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1645, in _send_handling_auth
response = await self._send_handling_redirects(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1682, in _send_handling_redirects
response = await self._send_single_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1719, in _send_single_request
response = await transport.handle_async_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 352, in handle_async_request
with map_httpcore_exceptions():
File "/usr/local/lib/python3.11/contextlib.py", line 155, in __exit__
self.gen.throw(typ, value, traceback)
File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
raise mapped_exc(message) from exc
httpx.ReadTimeout

Timings for each failed sensors

2023-09-04 21:38:27.144 Boot
2023-09-04 21:44:07.696 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.retour_maison_julien fails
2023-09-04 21:49:07.540 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.travail_julien fails
2023-09-04 21:54:07.938 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.travail_morgane fails
2023-09-04 21:54:07.938 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.travail_morgane fails
2023-09-04 22:09:07.227 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.retour_maison_morgane fails

Log timings for three sensors today

2023-09-04 07:19:47.131 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.retour_maison_julien fails
2023-09-04 07:29:47.194 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.retour_maison_julien fails
2023-09-04 09:14:47.703 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.retour_maison_julien fails
2023-09-04 10:14:47.360 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.retour_maison_julien fails
2023-09-04 10:44:47.268 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.retour_maison_julien fails
2023-09-04 12:59:48.290 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.retour_maison_julien fails
2023-09-04 13:09:48.318 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.retour_maison_julien fails
2023-09-04 13:44:48.478 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.retour_maison_julien fails
2023-09-04 13:49:48.255 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.retour_maison_julien fails
2023-09-04 14:19:48.382 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.retour_maison_julien fails
2023-09-04 14:34:48.361 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.retour_maison_julien fails
2023-09-04 14:54:48.439 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.retour_maison_julien fails
2023-09-04 15:49:48.443 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.retour_maison_julien fails
2023-09-04 16:19:48.541 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.retour_maison_julien fails
2023-09-04 20:09:48.673 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.retour_maison_julien fails
2023-09-04 20:34:48.801 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.retour_maison_julien fails
2023-09-04 21:04:48.908 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.retour_maison_julien fails
2023-09-04 08:14:47.346 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.travail_julien fails
2023-09-04 08:34:47.343 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.travail_julien fails
2023-09-04 08:54:47.271 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.travail_julien fails
2023-09-04 09:54:47.266 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.travail_julien fails
2023-09-04 10:29:47.488 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.travail_julien fails
2023-09-04 10:44:47.781 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.travail_julien fails
2023-09-04 11:29:47.373 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.travail_julien fails
2023-09-04 11:34:47.452 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.travail_julien fails
2023-09-04 12:24:48.492 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.travail_julien fails
2023-09-04 15:54:47.977 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.travail_julien_maison fails
2023-09-04 16:09:47.977 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.travail_julien_maison fails
2023-09-04 18:14:48.145 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.travail_julien_maison fails
2023-09-04 18:59:48.161 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.travail_julien_maison fails
2023-09-04 19:34:48.176 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.travail_julien_maison fails
2023-09-04 21:29:48.172 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.travail_julien_maison fails

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.