home-assistant-ecosystem / python-opendata-transport

Python client for interacting with transport.opendata.ch
MIT License
11 stars 9 forks source link

Next connection is skipped in result #7

Closed christophkreutzer closed 4 years ago

christophkreutzer commented 5 years ago

Hello

It seems like the next connection (in time) is skipped in the output.

E.g., I request a connection at 16:14. The response from the API includes a train at 16:19:

DEBUG:opendata_transport:{'connections': [{'from': {'station': {'id': '8508054', 'name': 'Worblaufen', 'score': None, 'coordinate': {'type': 'WGS84', 'x': 46.978839, 'y': 7.457629}, 'distance': None}, 'arrival': None, 'arrivalTimestamp': None, 'departure': '2019-07-31T16:19:00+0200', 'departureTimestamp': 1564582740, 'delay': 0, 'platform': '5', [...]

However, the output of example.py does not include this one, but the only the next:

Train connections: Worblaufen -> Bern
{0: {'departure': '2019-07-31T16:21:00+0200', 'duration': '00d00:05:00', 'transfers': 0, 'number': 'S8 8610', 'platform': '3'}, 1: {'departure': '2019-07-31T16:22:00+0200', 'duration': '00d00:07:00', 'transfers': 0, 'number': 'S9 9162', 'platform': '1'}, 2: {'departure': '2019-07-31T16:28:00+0200', 'duration': '00d00:05:00', 'transfers': 0, 'number': 'S8 8160', 'platform': '3'}}
{'departure': '2019-07-31T16:21:00+0200', 'duration': '00d00:05:00', 'transfers': 0, 'number': 'S8 8610', 'platform': '3'}

Probably has to do with the loop over the connections?

https://github.com/fabaff/python-opendata-transport/blob/774ced7d6ca50371b2ef65a07528d89a74c4b6fa/opendata_transport/__init__.py#L52

If I change this line to

            for conn in data['connections'][0:3]:

it shows the next connection as expected.

Thank you very much for the wrapper!