python-opendata-transport 0.3.0__tar.gz → 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. {python_opendata_transport-0.3.0 → python_opendata_transport-0.5.0}/.github/workflows/python.yml +7 -4
  2. {python_opendata_transport-0.3.0 → python_opendata_transport-0.5.0}/.gitignore +3 -0
  3. {python_opendata_transport-0.3.0 → python_opendata_transport-0.5.0}/CHANGES.txt +21 -0
  4. {python_opendata_transport-0.3.0 → python_opendata_transport-0.5.0}/LICENSE +1 -1
  5. {python_opendata_transport-0.3.0 → python_opendata_transport-0.5.0}/PKG-INFO +8 -9
  6. {python_opendata_transport-0.3.0 → python_opendata_transport-0.5.0}/README.rst +1 -1
  7. {python_opendata_transport-0.3.0 → python_opendata_transport-0.5.0}/example.py +23 -0
  8. python_opendata_transport-0.5.0/opendata_transport/__init__.py +317 -0
  9. {python_opendata_transport-0.3.0 → python_opendata_transport-0.5.0}/python_opendata_transport.egg-info/PKG-INFO +9 -10
  10. {python_opendata_transport-0.3.0 → python_opendata_transport-0.5.0}/python_opendata_transport.egg-info/SOURCES.txt +0 -2
  11. python_opendata_transport-0.5.0/python_opendata_transport.egg-info/requires.txt +2 -0
  12. {python_opendata_transport-0.3.0 → python_opendata_transport-0.5.0}/setup.py +5 -5
  13. python_opendata_transport-0.3.0/Pipfile +0 -12
  14. python_opendata_transport-0.3.0/Pipfile.lock +0 -186
  15. python_opendata_transport-0.3.0/opendata_transport/__init__.py +0 -156
  16. python_opendata_transport-0.3.0/python_opendata_transport.egg-info/requires.txt +0 -2
  17. {python_opendata_transport-0.3.0 → python_opendata_transport-0.5.0}/MANIFEST.in +0 -0
  18. {python_opendata_transport-0.3.0 → python_opendata_transport-0.5.0}/opendata_transport/exceptions.py +0 -0
  19. {python_opendata_transport-0.3.0 → python_opendata_transport-0.5.0}/python_opendata_transport.egg-info/dependency_links.txt +0 -0
  20. {python_opendata_transport-0.3.0 → python_opendata_transport-0.5.0}/python_opendata_transport.egg-info/top_level.txt +0 -0
  21. {python_opendata_transport-0.3.0 → python_opendata_transport-0.5.0}/python_opendata_transport.egg-info/zip-safe +0 -0
  22. {python_opendata_transport-0.3.0 → python_opendata_transport-0.5.0}/setup.cfg +0 -0
@@ -12,17 +12,20 @@ jobs:
12
12
  runs-on: ubuntu-latest
13
13
  strategy:
14
14
  matrix:
15
- python-version: [ 3.8, 3.9 ]
15
+ python-version: [ "3.11", "3.12" ]
16
16
 
17
17
  steps:
18
- - uses: actions/checkout@v2
18
+ - uses: actions/checkout@v4
19
+
19
20
  - name: Set up Python ${{ matrix.python-version }}
20
- uses: actions/setup-python@v2
21
+ uses: actions/setup-python@v5
21
22
  with:
22
23
  python-version: ${{ matrix.python-version }}
24
+
23
25
  - name: Install dependencies
24
26
  run: |
25
27
  python -m pip install --upgrade pip
26
28
  python setup.py install
29
+
27
30
  - name: Black Code Formatter
28
- uses: lgeiger/black-action@v1.0.1
31
+ uses: jpetrucciani/black-check@22.12.0
@@ -99,3 +99,6 @@ ENV/
99
99
 
100
100
  # mypy
101
101
  .mypy_cache/
102
+
103
+ # PyCharm
104
+ .idea
@@ -1,6 +1,27 @@
1
1
  Changes
2
2
  =======
3
3
 
4
+ 20240929 - 0.5.0
5
+ ----------------
6
+
7
+ - Chain errors to be more transparent to the error source (thanks @miaucl)
8
+ - Add KeyError exception (thanks @miaucl)
9
+ - Add line numbers (thanks @polgarc)
10
+
11
+ 20231120 - 0.4.0
12
+ ----------------
13
+
14
+ - Add support locations API (thanks @miaucl)
15
+ - Add missing connections parameters (thanks @miaucl)
16
+ - Add missing stationboard parameters (thanks @miaucl)
17
+ - Add "True" flag for correct formatting of lists (ex. via parameter `via[]=foo1&via[]=foo2`) (thanks @miaucl)
18
+
19
+ 20211124 - 0.3.0
20
+ ----------------
21
+
22
+ - Don't use async timeout (thanks @agners)
23
+ - Remove loop
24
+
4
25
  20210317 - 0.2.2
5
26
  ----------------
6
27
 
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017-2020 Fabian Affolter <fabian@affolter-engineering.ch>
3
+ Copyright (c) 2017-2024 Fabian Affolter <fabian@affolter-engineering.ch>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,13 +1,12 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python_opendata_transport
3
- Version: 0.3.0
3
+ Version: 0.5.0
4
4
  Summary: Python API for interacting with transport.opendata.ch.
5
5
  Home-page: https://github.com/home-assistant-ecosystem/python-opendata-transport
6
+ Download-URL: https://github.com/home-assistant-ecosystem/python-opendata-transport/releases
6
7
  Author: Fabian Affolter
7
8
  Author-email: fabian@affolter-engineering.ch
8
9
  License: MIT
9
- Download-URL: https://github.com/home-assistant-ecosystem/python-opendata-transport/releases
10
- Platform: UNKNOWN
11
10
  Classifier: Development Status :: 3 - Alpha
12
11
  Classifier: Environment :: Console
13
12
  Classifier: Intended Audience :: Developers
@@ -15,11 +14,13 @@ Classifier: License :: OSI Approved :: MIT License
15
14
  Classifier: Operating System :: MacOS :: MacOS X
16
15
  Classifier: Operating System :: Microsoft :: Windows
17
16
  Classifier: Operating System :: POSIX
18
- Classifier: Programming Language :: Python :: 3.8
19
- Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
20
19
  Classifier: Topic :: Utilities
21
- Requires-Python: >=3.8
20
+ Requires-Python: >=3.11
22
21
  License-File: LICENSE
22
+ Requires-Dist: aiohttp<4,>=3.8.5
23
+ Requires-Dist: urllib3
23
24
 
24
25
  python-opendata-transport
25
26
  =========================
@@ -51,7 +52,7 @@ be present in the ``unstable`` channel.
51
52
 
52
53
  .. code:: bash
53
54
 
54
- $ nix-env -iA nixos.python39Packages.python-opendata-transport
55
+ $ nix-env -iA nixos.python3Packages.python-opendata-transport
55
56
 
56
57
  Usage
57
58
  -----
@@ -62,5 +63,3 @@ License
62
63
  -------
63
64
 
64
65
  ``python-opendata-transport`` is licensed under MIT, for more details check LICENSE.
65
-
66
-
@@ -28,7 +28,7 @@ be present in the ``unstable`` channel.
28
28
 
29
29
  .. code:: bash
30
30
 
31
- $ nix-env -iA nixos.python39Packages.python-opendata-transport
31
+ $ nix-env -iA nixos.python3Packages.python-opendata-transport
32
32
 
33
33
  Usage
34
34
  -----
@@ -5,11 +5,34 @@ import aiohttp
5
5
 
6
6
  from opendata_transport import OpendataTransport
7
7
  from opendata_transport import OpendataTransportStationboard
8
+ from opendata_transport import OpendataTransportLocation
8
9
 
9
10
 
10
11
  async def main():
11
12
  """Example for getting the data."""
12
13
  async with aiohttp.ClientSession() as session:
14
+ # Search a station by query
15
+ locations = OpendataTransportLocation(session, query="Stettb")
16
+ await locations.async_get_data()
17
+
18
+ # Print the locations data
19
+ print(locations.locations)
20
+
21
+ # Print as list
22
+ print(list(map(lambda x: x["name"], locations.locations)))
23
+
24
+ # Search a station by coordinates
25
+ locations = OpendataTransportLocation(session, x=47.2, y=8.7)
26
+ await locations.async_get_data()
27
+
28
+ # Print the locations data
29
+ print(locations.locations)
30
+
31
+ # Print as list
32
+ print(list(map(lambda x: x["name"], locations.locations)))
33
+
34
+ print()
35
+
13
36
  # Get the connection for a defined route
14
37
  connection = OpendataTransport(
15
38
  "Zürich, Blumenfeldstrasse", "Zürich Oerlikon, Bahnhof", session, 4
@@ -0,0 +1,317 @@
1
+ """Wrapper to get connection details from Opendata Transport."""
2
+ import asyncio
3
+ import logging
4
+
5
+ import aiohttp
6
+ import urllib.parse
7
+
8
+ from . import exceptions
9
+
10
+ _LOGGER = logging.getLogger(__name__)
11
+ _RESOURCE_URL = "http://transport.opendata.ch/v1/"
12
+
13
+
14
+ class OpendataTransportBase(object):
15
+ """Representation of the Opendata Transport base class"""
16
+
17
+ def __init__(self, session):
18
+ self._session = session
19
+
20
+ @staticmethod
21
+ def get_url(resource, params):
22
+ """Generate the URL for the request."""
23
+ param = urllib.parse.urlencode(params, True)
24
+ url = "{resource_url}{resource}?{param}".format(
25
+ resource_url=_RESOURCE_URL, resource=resource, param=param
26
+ )
27
+ print(url)
28
+ return url
29
+
30
+
31
+ class OpendataTransportLocation(OpendataTransportBase):
32
+ """A class for handling locations from Opendata Transport."""
33
+
34
+ def __init__(self, session, query=None, x=None, y=None, type_="all", fields=None):
35
+ """Initialize the location."""
36
+ super().__init__(session)
37
+
38
+ self.query = query
39
+ self.x = x
40
+ self.y = y
41
+ self.type = type_
42
+ self.fields = (
43
+ fields if fields is not None and isinstance(fields, list) else None
44
+ )
45
+
46
+ self.from_name = self.from_id = self.to_name = self.to_id = None
47
+
48
+ self.locations = []
49
+
50
+ @staticmethod
51
+ def get_station(station):
52
+ """Get the station details."""
53
+ return {
54
+ "name": station["name"],
55
+ "score": station["score"],
56
+ "coordinate_type": station["coordinate"]["type"],
57
+ "x": station["coordinate"]["x"],
58
+ "y": station["coordinate"]["y"],
59
+ "distance": station["distance"],
60
+ }
61
+
62
+ async def async_get_data(self):
63
+ """Retrieve the data for the location."""
64
+ params = {}
65
+ if self.query is not None:
66
+ params["query"] = self.query
67
+ else:
68
+ params["x"] = self.x
69
+ params["y"] = self.y
70
+
71
+ if self.fields:
72
+ params["fields"] = self.fields
73
+
74
+ url = self.get_url("locations", params)
75
+
76
+ try:
77
+ response = await self._session.get(url, raise_for_status=True)
78
+
79
+ _LOGGER.debug("Response from transport.opendata.ch: %s", response.status)
80
+ data = await response.json()
81
+ _LOGGER.debug(data)
82
+ except asyncio.TimeoutError as e:
83
+ _LOGGER.error("Can not load data from transport.opendata.ch")
84
+ raise exceptions.OpendataTransportConnectionError() from e
85
+ except aiohttp.ClientError as aiohttpClientError:
86
+ _LOGGER.error("Response from transport.opendata.ch: %s", aiohttpClientError)
87
+ raise exceptions.OpendataTransportConnectionError() from aiohttpClientError
88
+
89
+ try:
90
+ for station in data["stations"]:
91
+ self.locations.append(self.get_station(station))
92
+ except (KeyError, TypeError, IndexError) as e:
93
+ raise exceptions.OpendataTransportError() from e
94
+
95
+
96
+ class OpendataTransportStationboard(OpendataTransportBase):
97
+ """A class for handling stationsboards from Opendata Transport."""
98
+
99
+ def __init__(
100
+ self,
101
+ station,
102
+ session,
103
+ limit=5,
104
+ transportations=None,
105
+ datetime=None,
106
+ type_="departure",
107
+ fields=None,
108
+ ):
109
+ """Initialize the journey."""
110
+ super().__init__(session)
111
+
112
+ self.station = station
113
+ self.limit = limit
114
+ self.datetime = datetime
115
+ self.transportations = (
116
+ transportations
117
+ if transportations is not None and isinstance(transportations, list)
118
+ else None
119
+ )
120
+ self.type = type_
121
+ self.fields = (
122
+ fields if fields is not None and isinstance(fields, list) else None
123
+ )
124
+
125
+ self.from_name = self.from_id = self.to_name = self.to_id = None
126
+
127
+ self.journeys = []
128
+
129
+ @staticmethod
130
+ def get_journey(journey):
131
+ """Get the journey details."""
132
+ return {
133
+ "departure": journey["stop"]["departure"],
134
+ "delay": journey["stop"]["delay"],
135
+ "platform": journey["stop"]["platform"],
136
+ "name": journey["name"],
137
+ "category": journey["category"],
138
+ "number": journey["number"],
139
+ "to": journey["to"],
140
+ }
141
+
142
+ async def __async_get_data(self, station):
143
+ """Retrieve the data for the station."""
144
+ params = {
145
+ "limit": self.limit,
146
+ "type": self.type,
147
+ }
148
+ if str.isdigit(station):
149
+ params["id"] = station
150
+ else:
151
+ params["station"] = station
152
+ if self.datetime:
153
+ params["datetime"] = self.date
154
+ if self.transportations:
155
+ params["transportations"] = self.transportations
156
+ if self.fields:
157
+ params["fields"] = self.fields
158
+
159
+ url = self.get_url("stationboard", params)
160
+
161
+ try:
162
+ response = await self._session.get(url, raise_for_status=True)
163
+
164
+ _LOGGER.debug("Response from transport.opendata.ch: %s", response.status)
165
+ data = await response.json()
166
+ _LOGGER.debug(data)
167
+ except asyncio.TimeoutError as e:
168
+ _LOGGER.error("Can not load data from transport.opendata.ch")
169
+ raise exceptions.OpendataTransportConnectionError() from e
170
+ except aiohttp.ClientError as aiohttpClientError:
171
+ _LOGGER.error("Response from transport.opendata.ch: %s", aiohttpClientError)
172
+ raise exceptions.OpendataTransportConnectionError() from aiohttpClientError
173
+
174
+ try:
175
+ for journey in data["stationboard"]:
176
+ self.journeys.append(self.get_journey(journey))
177
+ except (KeyError, TypeError, IndexError) as e:
178
+ raise exceptions.OpendataTransportError() from e
179
+
180
+ async def async_get_data(self):
181
+ """Retrieve the data for the given station."""
182
+ self.journeys = []
183
+ if isinstance(self.station, list):
184
+ for station in self.station:
185
+ await self.__async_get_data(station)
186
+ list.sort(self.journeys, key=lambda journey: journey["departure"])
187
+ else:
188
+ await self.__async_get_data(self.station)
189
+
190
+
191
+ class OpendataTransport(OpendataTransportBase):
192
+ """A class for handling connections from Opendata Transport."""
193
+
194
+ def __init__(
195
+ self,
196
+ start,
197
+ destination,
198
+ session,
199
+ limit=3,
200
+ page=0,
201
+ date=None,
202
+ time=None,
203
+ isArrivalTime=False,
204
+ transportations=None,
205
+ direct=False,
206
+ sleeper=False,
207
+ couchette=False,
208
+ bike=False,
209
+ accessibility=None,
210
+ via=None,
211
+ fields=None,
212
+ ):
213
+ """Initialize the connection."""
214
+ super().__init__(session)
215
+
216
+ self.limit = limit
217
+ self.page = page
218
+ self.start = start
219
+ self.destination = destination
220
+ self.via = via[:5] if via is not None and isinstance(via, list) else None
221
+ self.date = date
222
+ self.time = time
223
+ self.isArrivalTime = 1 if isArrivalTime else 0
224
+ self.transportations = (
225
+ transportations
226
+ if transportations is not None and isinstance(transportations, list)
227
+ else None
228
+ )
229
+ self.direct = 1 if direct else 0
230
+ self.sleeper = 1 if sleeper else 0
231
+ self.couchette = 1 if couchette else 0
232
+ self.bike = 1 if bike else 0
233
+ self.accessibility = accessibility
234
+ self.fields = (
235
+ fields if fields is not None and isinstance(fields, list) else None
236
+ )
237
+
238
+ self.from_name = self.from_id = self.to_name = self.to_id = None
239
+
240
+ self.connections = dict()
241
+
242
+ @staticmethod
243
+ def get_connection(connection):
244
+ """Get the connection details."""
245
+ connection_info = dict()
246
+ connection_info["departure"] = connection["from"]["departure"]
247
+ connection_info["duration"] = connection["duration"]
248
+ connection_info["delay"] = connection["from"]["delay"]
249
+ connection_info["transfers"] = connection["transfers"]
250
+
251
+ # Sections journey can be null if there is a walking section at first
252
+ connection_info["number"] = ""
253
+ for section in connection["sections"]:
254
+ if section["journey"] is not None:
255
+ journey = section["journey"]
256
+ connection_info["number"] = journey["name"]
257
+ connection_info["line"] = "".join(
258
+ filter(None, [journey["category"], journey["number"]])
259
+ )
260
+ break
261
+
262
+ connection_info["platform"] = connection["from"]["platform"]
263
+
264
+ return connection_info
265
+
266
+ async def async_get_data(self):
267
+ """Retrieve the data for the connection."""
268
+ params = {
269
+ "from": self.start,
270
+ "to": self.destination,
271
+ "limit": self.limit,
272
+ "page": self.page,
273
+ "isArrivalTime": self.isArrivalTime,
274
+ "direct": self.direct,
275
+ "sleeper": self.sleeper,
276
+ "couchette": self.couchette,
277
+ "bike": self.bike,
278
+ }
279
+ if self.via:
280
+ params["via"] = self.via
281
+ if self.time:
282
+ params["time"] = self.time
283
+ if self.date:
284
+ params["date"] = self.date
285
+ if self.transportations:
286
+ params["transportations"] = self.transportations
287
+ if self.accessibility:
288
+ params["accessibility"] = self.accessibility
289
+ if self.fields:
290
+ params["fields"] = self.fields
291
+
292
+ url = self.get_url("connections", params)
293
+
294
+ try:
295
+ response = await self._session.get(url, raise_for_status=True)
296
+
297
+ _LOGGER.debug("Response from transport.opendata.ch: %s", response.status)
298
+ data = await response.json()
299
+ _LOGGER.debug(data)
300
+ except asyncio.TimeoutError as e:
301
+ _LOGGER.error("Can not load data from transport.opendata.ch")
302
+ raise exceptions.OpendataTransportConnectionError() from e
303
+ except aiohttp.ClientError as aiohttpClientError:
304
+ _LOGGER.error("Response from transport.opendata.ch: %s", aiohttpClientError)
305
+ raise exceptions.OpendataTransportConnectionError() from aiohttpClientError
306
+
307
+ try:
308
+ self.from_id = data["from"]["id"]
309
+ self.from_name = data["from"]["name"]
310
+ self.to_id = data["to"]["id"]
311
+ self.to_name = data["to"]["name"]
312
+ index = 0
313
+ for connection in data["connections"]:
314
+ self.connections[index] = self.get_connection(connection)
315
+ index = index + 1
316
+ except (KeyError, TypeError, IndexError) as e:
317
+ raise exceptions.OpendataTransportError() from e
@@ -1,13 +1,12 @@
1
1
  Metadata-Version: 2.1
2
- Name: python-opendata-transport
3
- Version: 0.3.0
2
+ Name: python_opendata_transport
3
+ Version: 0.5.0
4
4
  Summary: Python API for interacting with transport.opendata.ch.
5
5
  Home-page: https://github.com/home-assistant-ecosystem/python-opendata-transport
6
+ Download-URL: https://github.com/home-assistant-ecosystem/python-opendata-transport/releases
6
7
  Author: Fabian Affolter
7
8
  Author-email: fabian@affolter-engineering.ch
8
9
  License: MIT
9
- Download-URL: https://github.com/home-assistant-ecosystem/python-opendata-transport/releases
10
- Platform: UNKNOWN
11
10
  Classifier: Development Status :: 3 - Alpha
12
11
  Classifier: Environment :: Console
13
12
  Classifier: Intended Audience :: Developers
@@ -15,11 +14,13 @@ Classifier: License :: OSI Approved :: MIT License
15
14
  Classifier: Operating System :: MacOS :: MacOS X
16
15
  Classifier: Operating System :: Microsoft :: Windows
17
16
  Classifier: Operating System :: POSIX
18
- Classifier: Programming Language :: Python :: 3.8
19
- Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
20
19
  Classifier: Topic :: Utilities
21
- Requires-Python: >=3.8
20
+ Requires-Python: >=3.11
22
21
  License-File: LICENSE
22
+ Requires-Dist: aiohttp<4,>=3.8.5
23
+ Requires-Dist: urllib3
23
24
 
24
25
  python-opendata-transport
25
26
  =========================
@@ -51,7 +52,7 @@ be present in the ``unstable`` channel.
51
52
 
52
53
  .. code:: bash
53
54
 
54
- $ nix-env -iA nixos.python39Packages.python-opendata-transport
55
+ $ nix-env -iA nixos.python3Packages.python-opendata-transport
55
56
 
56
57
  Usage
57
58
  -----
@@ -62,5 +63,3 @@ License
62
63
  -------
63
64
 
64
65
  ``python-opendata-transport`` is licensed under MIT, for more details check LICENSE.
65
-
66
-
@@ -2,8 +2,6 @@
2
2
  CHANGES.txt
3
3
  LICENSE
4
4
  MANIFEST.in
5
- Pipfile
6
- Pipfile.lock
7
5
  README.rst
8
6
  example.py
9
7
  setup.cfg
@@ -0,0 +1,2 @@
1
+ aiohttp<4,>=3.8.5
2
+ urllib3
@@ -12,7 +12,7 @@ with open(os.path.join(here, "README.rst"), encoding="utf-8") as readme:
12
12
 
13
13
  setup(
14
14
  name="python_opendata_transport",
15
- version="0.3.0",
15
+ version="0.5.0",
16
16
  description="Python API for interacting with transport.opendata.ch.",
17
17
  long_description=long_description,
18
18
  url="https://github.com/home-assistant-ecosystem/python-opendata-transport",
@@ -21,11 +21,11 @@ setup(
21
21
  author_email="fabian@affolter-engineering.ch",
22
22
  license="MIT",
23
23
  install_requires=[
24
- "aiohttp>=3.7.4,<4",
24
+ "aiohttp>=3.8.5,<4",
25
25
  "urllib3",
26
26
  ],
27
27
  packages=find_packages(),
28
- python_requires=">=3.8",
28
+ python_requires=">=3.11",
29
29
  zip_safe=True,
30
30
  classifiers=[
31
31
  "Development Status :: 3 - Alpha",
@@ -35,8 +35,8 @@ setup(
35
35
  "Operating System :: MacOS :: MacOS X",
36
36
  "Operating System :: Microsoft :: Windows",
37
37
  "Operating System :: POSIX",
38
- "Programming Language :: Python :: 3.8",
39
- "Programming Language :: Python :: 3.9",
38
+ "Programming Language :: Python :: 3.11",
39
+ "Programming Language :: Python :: 3.12",
40
40
  "Topic :: Utilities",
41
41
  ],
42
42
  )
@@ -1,12 +0,0 @@
1
- [[source]]
2
- url = "https://pypi.org/simple"
3
- verify_ssl = true
4
- name = "pypi"
5
-
6
- [dev-packages]
7
-
8
- [packages]
9
- aiohttp = "*"
10
-
11
- [requires]
12
- python_version = "
@@ -1,186 +0,0 @@
1
- {
2
- "_meta": {
3
- "hash": {
4
- "sha256": "2fd5f13a55dc19bec2affba9547da54c98c446a87e3d3c947a302cc914c0b94d"
5
- },
6
- "pipfile-spec": 6,
7
- "requires": {
8
- "python_version": "3.7"
9
- },
10
- "sources": [
11
- {
12
- "name": "pypi",
13
- "url": "https://pypi.org/simple",
14
- "verify_ssl": true
15
- }
16
- ]
17
- },
18
- "default": {
19
- "aiohttp": {
20
- "hashes": [
21
- "sha256:119feb2bd551e58d83d1b38bfa4cb921af8ddedec9fad7183132db334c3133e0",
22
- "sha256:16d0683ef8a6d803207f02b899c928223eb219111bd52420ef3d7a8aa76227b6",
23
- "sha256:2eb3efe243e0f4ecbb654b08444ae6ffab37ac0ef8f69d3a2ffb958905379daf",
24
- "sha256:2ffea7904e70350da429568113ae422c88d2234ae776519549513c8f217f58a9",
25
- "sha256:40bd1b101b71a18a528ffce812cc14ff77d4a2a1272dfb8b11b200967489ef3e",
26
- "sha256:418597633b5cd9639e514b1d748f358832c08cd5d9ef0870026535bd5eaefdd0",
27
- "sha256:481d4b96969fbfdcc3ff35eea5305d8565a8300410d3d269ccac69e7256b1329",
28
- "sha256:4c1bdbfdd231a20eee3e56bd0ac1cd88c4ff41b64ab679ed65b75c9c74b6c5c2",
29
- "sha256:5563ad7fde451b1986d42b9bb9140e2599ecf4f8e42241f6da0d3d624b776f40",
30
- "sha256:58c62152c4c8731a3152e7e650b29ace18304d086cb5552d317a54ff2749d32a",
31
- "sha256:5b50e0b9460100fe05d7472264d1975f21ac007b35dcd6fd50279b72925a27f4",
32
- "sha256:5d84ecc73141d0a0d61ece0742bb7ff5751b0657dab8405f899d3ceb104cc7de",
33
- "sha256:5dde6d24bacac480be03f4f864e9a67faac5032e28841b00533cd168ab39cad9",
34
- "sha256:5e91e927003d1ed9283dee9abcb989334fc8e72cf89ebe94dc3e07e3ff0b11e9",
35
- "sha256:62bc216eafac3204877241569209d9ba6226185aa6d561c19159f2e1cbb6abfb",
36
- "sha256:6c8200abc9dc5f27203986100579fc19ccad7a832c07d2bc151ce4ff17190076",
37
- "sha256:6ca56bdfaf825f4439e9e3673775e1032d8b6ea63b8953d3812c71bd6a8b81de",
38
- "sha256:71680321a8a7176a58dfbc230789790639db78dad61a6e120b39f314f43f1907",
39
- "sha256:7c7820099e8b3171e54e7eedc33e9450afe7cd08172632d32128bd527f8cb77d",
40
- "sha256:7dbd087ff2f4046b9b37ba28ed73f15fd0bc9f4fdc8ef6781913da7f808d9536",
41
- "sha256:822bd4fd21abaa7b28d65fc9871ecabaddc42767884a626317ef5b75c20e8a2d",
42
- "sha256:8ec1a38074f68d66ccb467ed9a673a726bb397142c273f90d4ba954666e87d54",
43
- "sha256:950b7ef08b2afdab2488ee2edaff92a03ca500a48f1e1aaa5900e73d6cf992bc",
44
- "sha256:99c5a5bf7135607959441b7d720d96c8e5c46a1f96e9d6d4c9498be8d5f24212",
45
- "sha256:b84ad94868e1e6a5e30d30ec419956042815dfaea1b1df1cef623e4564c374d9",
46
- "sha256:bc3d14bf71a3fb94e5acf5bbf67331ab335467129af6416a437bd6024e4f743d",
47
- "sha256:c2a80fd9a8d7e41b4e38ea9fe149deed0d6aaede255c497e66b8213274d6d61b",
48
- "sha256:c44d3c82a933c6cbc21039326767e778eface44fca55c65719921c4b9661a3f7",
49
- "sha256:cc31e906be1cc121ee201adbdf844522ea3349600dd0a40366611ca18cd40e81",
50
- "sha256:d5d102e945ecca93bcd9801a7bb2fa703e37ad188a2f81b1e65e4abe4b51b00c",
51
- "sha256:dd7936f2a6daa861143e376b3a1fb56e9b802f4980923594edd9ca5670974895",
52
- "sha256:dee68ec462ff10c1d836c0ea2642116aba6151c6880b688e56b4c0246770f297",
53
- "sha256:e76e78863a4eaec3aee5722d85d04dcbd9844bc6cd3bfa6aa880ff46ad16bfcb",
54
- "sha256:eab51036cac2da8a50d7ff0ea30be47750547c9aa1aa2cf1a1b710a1827e7dbe",
55
- "sha256:f4496d8d04da2e98cc9133e238ccebf6a13ef39a93da2e87146c8c8ac9768242",
56
- "sha256:fbd3b5e18d34683decc00d9a360179ac1e7a320a5fee10ab8053ffd6deab76e0",
57
- "sha256:feb24ff1226beeb056e247cf2e24bba5232519efb5645121c4aea5b6ad74c1f2"
58
- ],
59
- "index": "pypi",
60
- "version": "==3.7.4"
61
- },
62
- "async-timeout": {
63
- "hashes": [
64
- "sha256:0c3c816a028d47f659d6ff5c745cb2acf1f966da1fe5c19c77a70282b25f4c5f",
65
- "sha256:4291ca197d287d274d0b6cb5d6f8f8f82d434ed288f962539ff18cc9012f9ea3"
66
- ],
67
- "index": "pypi",
68
- "version": "==3.0.1"
69
- },
70
- "attrs": {
71
- "hashes": [
72
- "sha256:31b2eced602aa8423c2aea9c76a724617ed67cf9513173fd3a4f03e3a929c7e6",
73
- "sha256:832aa3cde19744e49938b91fea06d69ecb9e649c93ba974535d08ad92164f700"
74
- ],
75
- "version": "==20.3.0"
76
- },
77
- "chardet": {
78
- "hashes": [
79
- "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae",
80
- "sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691"
81
- ],
82
- "version": "==3.0.4"
83
- },
84
- "idna": {
85
- "hashes": [
86
- "sha256:5205d03e7bcbb919cc9c19885f9920d622ca52448306f2377daede5cf3faac16",
87
- "sha256:c5b02147e01ea9920e6b0a3f1f7bb833612d507592c837a6c49552768f4054e1"
88
- ],
89
- "version": "==3.1"
90
- },
91
- "multidict": {
92
- "hashes": [
93
- "sha256:018132dbd8688c7a69ad89c4a3f39ea2f9f33302ebe567a879da8f4ca73f0d0a",
94
- "sha256:051012ccee979b2b06be928a6150d237aec75dd6bf2d1eeeb190baf2b05abc93",
95
- "sha256:05c20b68e512166fddba59a918773ba002fdd77800cad9f55b59790030bab632",
96
- "sha256:07b42215124aedecc6083f1ce6b7e5ec5b50047afa701f3442054373a6deb656",
97
- "sha256:0e3c84e6c67eba89c2dbcee08504ba8644ab4284863452450520dad8f1e89b79",
98
- "sha256:0e929169f9c090dae0646a011c8b058e5e5fb391466016b39d21745b48817fd7",
99
- "sha256:1ab820665e67373de5802acae069a6a05567ae234ddb129f31d290fc3d1aa56d",
100
- "sha256:25b4e5f22d3a37ddf3effc0710ba692cfc792c2b9edfb9c05aefe823256e84d5",
101
- "sha256:2e68965192c4ea61fff1b81c14ff712fc7dc15d2bd120602e4a3494ea6584224",
102
- "sha256:2f1a132f1c88724674271d636e6b7351477c27722f2ed789f719f9e3545a3d26",
103
- "sha256:37e5438e1c78931df5d3c0c78ae049092877e5e9c02dd1ff5abb9cf27a5914ea",
104
- "sha256:3a041b76d13706b7fff23b9fc83117c7b8fe8d5fe9e6be45eee72b9baa75f348",
105
- "sha256:3a4f32116f8f72ecf2a29dabfb27b23ab7cdc0ba807e8459e59a93a9be9506f6",
106
- "sha256:46c73e09ad374a6d876c599f2328161bcd95e280f84d2060cf57991dec5cfe76",
107
- "sha256:46dd362c2f045095c920162e9307de5ffd0a1bfbba0a6e990b344366f55a30c1",
108
- "sha256:4b186eb7d6ae7c06eb4392411189469e6a820da81447f46c0072a41c748ab73f",
109
- "sha256:54fd1e83a184e19c598d5e70ba508196fd0bbdd676ce159feb412a4a6664f952",
110
- "sha256:585fd452dd7782130d112f7ddf3473ffdd521414674c33876187e101b588738a",
111
- "sha256:5cf3443199b83ed9e955f511b5b241fd3ae004e3cb81c58ec10f4fe47c7dce37",
112
- "sha256:6a4d5ce640e37b0efcc8441caeea8f43a06addace2335bd11151bc02d2ee31f9",
113
- "sha256:7df80d07818b385f3129180369079bd6934cf70469f99daaebfac89dca288359",
114
- "sha256:806068d4f86cb06af37cd65821554f98240a19ce646d3cd24e1c33587f313eb8",
115
- "sha256:830f57206cc96ed0ccf68304141fec9481a096c4d2e2831f311bde1c404401da",
116
- "sha256:929006d3c2d923788ba153ad0de8ed2e5ed39fdbe8e7be21e2f22ed06c6783d3",
117
- "sha256:9436dc58c123f07b230383083855593550c4d301d2532045a17ccf6eca505f6d",
118
- "sha256:9dd6e9b1a913d096ac95d0399bd737e00f2af1e1594a787e00f7975778c8b2bf",
119
- "sha256:ace010325c787c378afd7f7c1ac66b26313b3344628652eacd149bdd23c68841",
120
- "sha256:b47a43177a5e65b771b80db71e7be76c0ba23cc8aa73eeeb089ed5219cdbe27d",
121
- "sha256:b797515be8743b771aa868f83563f789bbd4b236659ba52243b735d80b29ed93",
122
- "sha256:b7993704f1a4b204e71debe6095150d43b2ee6150fa4f44d6d966ec356a8d61f",
123
- "sha256:d5c65bdf4484872c4af3150aeebe101ba560dcfb34488d9a8ff8dbcd21079647",
124
- "sha256:d81eddcb12d608cc08081fa88d046c78afb1bf8107e6feab5d43503fea74a635",
125
- "sha256:dc862056f76443a0db4509116c5cd480fe1b6a2d45512a653f9a855cc0517456",
126
- "sha256:ecc771ab628ea281517e24fd2c52e8f31c41e66652d07599ad8818abaad38cda",
127
- "sha256:f200755768dc19c6f4e2b672421e0ebb3dd54c38d5a4f262b872d8cfcc9e93b5",
128
- "sha256:f21756997ad8ef815d8ef3d34edd98804ab5ea337feedcd62fb52d22bf531281",
129
- "sha256:fc13a9524bc18b6fb6e0dbec3533ba0496bbed167c56d0aabefd965584557d80"
130
- ],
131
- "version": "==5.1.0"
132
- },
133
- "typing-extensions": {
134
- "hashes": [
135
- "sha256:7cb407020f00f7bfc3cb3e7881628838e69d8f3fcab2f64742a5e76b2f841918",
136
- "sha256:99d4073b617d30288f569d3f13d2bd7548c3a7e4c8de87db09a9d29bb3a4a60c",
137
- "sha256:dafc7639cde7f1b6e1acc0f457842a83e722ccca8eef5270af2d74792619a89f"
138
- ],
139
- "markers": "python_version < '3.8'",
140
- "version": "==3.7.4.3"
141
- },
142
- "yarl": {
143
- "hashes": [
144
- "sha256:00d7ad91b6583602eb9c1d085a2cf281ada267e9a197e8b7cae487dadbfa293e",
145
- "sha256:0355a701b3998dcd832d0dc47cc5dedf3874f966ac7f870e0f3a6788d802d434",
146
- "sha256:15263c3b0b47968c1d90daa89f21fcc889bb4b1aac5555580d74565de6836366",
147
- "sha256:2ce4c621d21326a4a5500c25031e102af589edb50c09b321049e388b3934eec3",
148
- "sha256:31ede6e8c4329fb81c86706ba8f6bf661a924b53ba191b27aa5fcee5714d18ec",
149
- "sha256:324ba3d3c6fee56e2e0b0d09bf5c73824b9f08234339d2b788af65e60040c959",
150
- "sha256:329412812ecfc94a57cd37c9d547579510a9e83c516bc069470db5f75684629e",
151
- "sha256:4736eaee5626db8d9cda9eb5282028cc834e2aeb194e0d8b50217d707e98bb5c",
152
- "sha256:4953fb0b4fdb7e08b2f3b3be80a00d28c5c8a2056bb066169de00e6501b986b6",
153
- "sha256:4c5bcfc3ed226bf6419f7a33982fb4b8ec2e45785a0561eb99274ebbf09fdd6a",
154
- "sha256:547f7665ad50fa8563150ed079f8e805e63dd85def6674c97efd78eed6c224a6",
155
- "sha256:5b883e458058f8d6099e4420f0cc2567989032b5f34b271c0827de9f1079a424",
156
- "sha256:63f90b20ca654b3ecc7a8d62c03ffa46999595f0167d6450fa8383bab252987e",
157
- "sha256:68dc568889b1c13f1e4745c96b931cc94fdd0defe92a72c2b8ce01091b22e35f",
158
- "sha256:69ee97c71fee1f63d04c945f56d5d726483c4762845400a6795a3b75d56b6c50",
159
- "sha256:6d6283d8e0631b617edf0fd726353cb76630b83a089a40933043894e7f6721e2",
160
- "sha256:72a660bdd24497e3e84f5519e57a9ee9220b6f3ac4d45056961bf22838ce20cc",
161
- "sha256:73494d5b71099ae8cb8754f1df131c11d433b387efab7b51849e7e1e851f07a4",
162
- "sha256:7356644cbed76119d0b6bd32ffba704d30d747e0c217109d7979a7bc36c4d970",
163
- "sha256:8a9066529240171b68893d60dca86a763eae2139dd42f42106b03cf4b426bf10",
164
- "sha256:8aa3decd5e0e852dc68335abf5478a518b41bf2ab2f330fe44916399efedfae0",
165
- "sha256:97b5bdc450d63c3ba30a127d018b866ea94e65655efaf889ebeabc20f7d12406",
166
- "sha256:9ede61b0854e267fd565e7527e2f2eb3ef8858b301319be0604177690e1a3896",
167
- "sha256:b2e9a456c121e26d13c29251f8267541bd75e6a1ccf9e859179701c36a078643",
168
- "sha256:b5dfc9a40c198334f4f3f55880ecf910adebdcb2a0b9a9c23c9345faa9185721",
169
- "sha256:bafb450deef6861815ed579c7a6113a879a6ef58aed4c3a4be54400ae8871478",
170
- "sha256:c49ff66d479d38ab863c50f7bb27dee97c6627c5fe60697de15529da9c3de724",
171
- "sha256:ce3beb46a72d9f2190f9e1027886bfc513702d748047b548b05dab7dfb584d2e",
172
- "sha256:d26608cf178efb8faa5ff0f2d2e77c208f471c5a3709e577a7b3fd0445703ac8",
173
- "sha256:d597767fcd2c3dc49d6eea360c458b65643d1e4dbed91361cf5e36e53c1f8c96",
174
- "sha256:d5c32c82990e4ac4d8150fd7652b972216b204de4e83a122546dce571c1bdf25",
175
- "sha256:d8d07d102f17b68966e2de0e07bfd6e139c7c02ef06d3a0f8d2f0f055e13bb76",
176
- "sha256:e46fba844f4895b36f4c398c5af062a9808d1f26b2999c58909517384d5deda2",
177
- "sha256:e6b5460dc5ad42ad2b36cca524491dfcaffbfd9c8df50508bddc354e787b8dc2",
178
- "sha256:f040bcc6725c821a4c0665f3aa96a4d0805a7aaf2caf266d256b8ed71b9f041c",
179
- "sha256:f0b059678fd549c66b89bed03efcabb009075bd131c248ecdf087bdb6faba24a",
180
- "sha256:fcbb48a93e8699eae920f8d92f7160c03567b421bc17362a9ffbbd706a816f71"
181
- ],
182
- "version": "==1.6.3"
183
- }
184
- },
185
- "develop": {}
186
- }
@@ -1,156 +0,0 @@
1
- """Wrapper to get connection details from Opendata Transport."""
2
- import asyncio
3
- import logging
4
-
5
- import aiohttp
6
- import urllib.parse
7
-
8
- from . import exceptions
9
-
10
- _LOGGER = logging.getLogger(__name__)
11
- _RESOURCE_URL = "http://transport.opendata.ch/v1/"
12
-
13
-
14
- class OpendataTransportBase(object):
15
- """Representation of the Opendata Transport base class"""
16
-
17
- def __init__(self, session):
18
- self._session = session
19
-
20
- @staticmethod
21
- def get_url(resource, params):
22
- """Generate the URL for the request."""
23
- param = urllib.parse.urlencode(params)
24
- url = "{resource_url}{resource}?{param}".format(
25
- resource_url=_RESOURCE_URL, resource=resource, param=param
26
- )
27
- return url
28
-
29
-
30
- class OpendataTransportStationboard(OpendataTransportBase):
31
- """A class for handling stationsboards from Opendata Transport."""
32
-
33
- def __init__(self, station, session, limit=5):
34
- """Initialize the journey."""
35
- super().__init__(session)
36
- self.station = station
37
- self.limit = limit
38
- self.from_name = self.from_id = self.to_name = self.to_id = None
39
- self.journeys = []
40
-
41
- @staticmethod
42
- def get_journey(journey):
43
- """Get the journey details."""
44
- return {
45
- "departure": journey["stop"]["departure"],
46
- "delay": journey["stop"]["delay"],
47
- "platform": journey["stop"]["platform"],
48
- "name": journey["name"],
49
- "category": journey["category"],
50
- "number": journey["number"],
51
- "to": journey["to"],
52
- }
53
-
54
- async def __async_get_data(self, station):
55
- """Retrieve the data for the station."""
56
- params = {"limit": self.limit}
57
- if str.isdigit(station):
58
- params["id"] = station
59
- else:
60
- params["station"] = station
61
-
62
- url = self.get_url("stationboard", params)
63
-
64
- try:
65
- response = await self._session.get(url, raise_for_status=True)
66
-
67
- _LOGGER.debug("Response from transport.opendata.ch: %s", response.status)
68
- data = await response.json()
69
- _LOGGER.debug(data)
70
- except asyncio.TimeoutError:
71
- _LOGGER.error("Can not load data from transport.opendata.ch")
72
- raise exceptions.OpendataTransportConnectionError()
73
- except aiohttp.ClientError as aiohttpClientError:
74
- _LOGGER.error("Response from transport.opendata.ch: %s", aiohttpClientError)
75
- raise exceptions.OpendataTransportConnectionError()
76
-
77
- try:
78
- for journey in data["stationboard"]:
79
- self.journeys.append(self.get_journey(journey))
80
- except (TypeError, IndexError):
81
- raise exceptions.OpendataTransportError()
82
-
83
- async def async_get_data(self):
84
- """Retrieve the data for the given station."""
85
- self.journeys = []
86
- if isinstance(self.station, list):
87
- for station in self.station:
88
- await self.__async_get_data(station)
89
- list.sort(self.journeys, key=lambda journey: journey["departure"])
90
- else:
91
- await self.__async_get_data(self.station)
92
-
93
-
94
- class OpendataTransport(OpendataTransportBase):
95
- """A class for handling connections from Opendata Transport."""
96
-
97
- def __init__(self, start, destination, session, limit=3):
98
- """Initialize the connection."""
99
- super().__init__(session)
100
- self.limit = limit
101
- self.start = start
102
- self.destination = destination
103
- self.from_name = self.from_id = self.to_name = self.to_id = None
104
- self.connections = dict()
105
-
106
- @staticmethod
107
- def get_connection(connection):
108
- """Get the connection details."""
109
- connection_info = dict()
110
- connection_info["departure"] = connection["from"]["departure"]
111
- connection_info["duration"] = connection["duration"]
112
- connection_info["delay"] = connection["from"]["delay"]
113
- connection_info["transfers"] = connection["transfers"]
114
-
115
- # Sections journey can be null if there is a walking section at first
116
- connection_info["number"] = ""
117
- for section in connection["sections"]:
118
- if section["journey"] is not None:
119
- connection_info["number"] = section["journey"]["name"]
120
- break
121
-
122
- connection_info["platform"] = connection["from"]["platform"]
123
-
124
- return connection_info
125
-
126
- async def async_get_data(self):
127
- """Retrieve the data for the connection."""
128
- url = self.get_url(
129
- "connections",
130
- {"from": self.start, "to": self.destination, "limit": self.limit},
131
- )
132
-
133
- try:
134
- response = await self._session.get(url, raise_for_status=True)
135
-
136
- _LOGGER.debug("Response from transport.opendata.ch: %s", response.status)
137
- data = await response.json()
138
- _LOGGER.debug(data)
139
- except asyncio.TimeoutError:
140
- _LOGGER.error("Can not load data from transport.opendata.ch")
141
- raise exceptions.OpendataTransportConnectionError()
142
- except aiohttp.ClientError as aiohttpClientError:
143
- _LOGGER.error("Response from transport.opendata.ch: %s", aiohttpClientError)
144
- raise exceptions.OpendataTransportConnectionError()
145
-
146
- try:
147
- self.from_id = data["from"]["id"]
148
- self.from_name = data["from"]["name"]
149
- self.to_id = data["to"]["id"]
150
- self.to_name = data["to"]["name"]
151
- index = 0
152
- for connection in data["connections"]:
153
- self.connections[index] = self.get_connection(connection)
154
- index = index + 1
155
- except (TypeError, IndexError):
156
- raise exceptions.OpendataTransportError()
@@ -1,2 +0,0 @@
1
- aiohttp<4,>=3.7.4
2
- urllib3