helldog136 / pystibmivb

Python library to query STIB/MIVB opendata
Creative Commons Attribution 4.0 International
3 stars 2 forks source link

Catch error in get_location when stop_name is wrong #14

Closed danito closed 4 years ago

danito commented 4 years ago

Hi, when putting a unknown stop_name you get an error:

dan@jf26-x:~/scripts/stibXml2json$ python3 example.py 
Traceback (most recent call last):
  File "example.py", line 35, in <module>
    LOOP.run_until_complete(go(LOOP))
  File "/usr/lib/python3.6/asyncio/base_events.py", line 488, in run_until_complete
    return future.result()
  File "example.py", line 19, in go
    print(await service.get_passages(stop_name, lang_message="en", max_passages=1))
  File "/home/dan/.local/lib/python3.6/site-packages/pystibmivb/service/STIBService.py", line 35, in get_passages
    stop_infos) + " Provided line filter:" + str(line_filters))
  File "/home/dan/.local/lib/python3.6/site-packages/pystibmivb/domain/stop.py", line 82, in __str__
    return f"{self.stop_name}({self.get_location()}): {[str(k) for k in self.lines]}: {[str(v) for v in self.line_infos.values()]}"
  File "/home/dan/.local/lib/python3.6/site-packages/pystibmivb/domain/stop.py", line 95, in get_location
    return {"lat": sum(latitudes)/len(latitudes), "lon": sum(longitudes)/len(longitudes)}
ZeroDivisionError: division by zero
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f9c419a46a0>
helldog136 commented 4 years ago

Addd new raised exception to prevent this in 1.5.2