python-opendata-transport 0.1.4__tar.gz → 0.2.1__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.
- {python_opendata_transport-0.1.4 → python_opendata_transport-0.2.1}/LICENSE +1 -1
- {python_opendata_transport-0.1.4 → python_opendata_transport-0.2.1}/PKG-INFO +10 -4
- {python_opendata_transport-0.1.4 → python_opendata_transport-0.2.1}/README.rst +9 -3
- python_opendata_transport-0.2.1/opendata_transport/__init__.py +159 -0
- {python_opendata_transport-0.1.4 → python_opendata_transport-0.2.1}/python_opendata_transport.egg-info/PKG-INFO +10 -4
- {python_opendata_transport-0.1.4 → python_opendata_transport-0.2.1}/python_opendata_transport.egg-info/requires.txt +1 -0
- {python_opendata_transport-0.1.4 → python_opendata_transport-0.2.1}/setup.py +5 -9
- python_opendata_transport-0.1.4/opendata_transport/__init__.py +0 -67
- {python_opendata_transport-0.1.4 → python_opendata_transport-0.2.1}/MANIFEST.in +0 -0
- {python_opendata_transport-0.1.4 → python_opendata_transport-0.2.1}/opendata_transport/exceptions.py +0 -0
- {python_opendata_transport-0.1.4 → python_opendata_transport-0.2.1}/python_opendata_transport.egg-info/SOURCES.txt +0 -0
- {python_opendata_transport-0.1.4 → python_opendata_transport-0.2.1}/python_opendata_transport.egg-info/dependency_links.txt +0 -0
- {python_opendata_transport-0.1.4 → python_opendata_transport-0.2.1}/python_opendata_transport.egg-info/top_level.txt +0 -0
- {python_opendata_transport-0.1.4 → python_opendata_transport-0.2.1}/python_opendata_transport.egg-info/zip-safe +0 -0
- {python_opendata_transport-0.1.4 → python_opendata_transport-0.2.1}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2017 Fabian Affolter
|
|
3
|
+
Copyright (c) 2017-2020 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,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 1.1
|
|
2
2
|
Name: python_opendata_transport
|
|
3
|
-
Version: 0.1
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Python API for interacting with transport.opendata.ch.
|
|
5
5
|
Home-page: https://github.com/fabaff/python-opendata-transport
|
|
6
6
|
Author: Fabian Affolter
|
|
@@ -10,10 +10,10 @@ Download-URL: https://github.com/fabaff/python-opendata-transport/releases
|
|
|
10
10
|
Description: python-opendata-transport
|
|
11
11
|
=========================
|
|
12
12
|
|
|
13
|
-
Python
|
|
13
|
+
A Python client for interacting with `transport.opendata.ch <http://transport.opendata.ch/>`_.
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
is simply retrieving the details about a given connection between
|
|
15
|
+
This module is the base for the integration into `Home Assistant <https://home-assistant.io>`_
|
|
16
|
+
and is simply retrieving the details about a given connection between two stations.
|
|
17
17
|
|
|
18
18
|
This module is not official, developed, supported or endorsed by opendata.ch.
|
|
19
19
|
|
|
@@ -26,6 +26,12 @@ Description: python-opendata-transport
|
|
|
26
26
|
|
|
27
27
|
$ pip3 install python_opendata_transport
|
|
28
28
|
|
|
29
|
+
On a Fedora-based system.
|
|
30
|
+
|
|
31
|
+
.. code:: bash
|
|
32
|
+
|
|
33
|
+
$ sudo dnf -y install python3-opendata-transport
|
|
34
|
+
|
|
29
35
|
Usage
|
|
30
36
|
-----
|
|
31
37
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
python-opendata-transport
|
|
2
2
|
=========================
|
|
3
3
|
|
|
4
|
-
Python
|
|
4
|
+
A Python client for interacting with `transport.opendata.ch <http://transport.opendata.ch/>`_.
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
is simply retrieving the details about a given connection between
|
|
6
|
+
This module is the base for the integration into `Home Assistant <https://home-assistant.io>`_
|
|
7
|
+
and is simply retrieving the details about a given connection between two stations.
|
|
8
8
|
|
|
9
9
|
This module is not official, developed, supported or endorsed by opendata.ch.
|
|
10
10
|
|
|
@@ -17,6 +17,12 @@ The module is available from the `Python Package Index <https://pypi.python.org/
|
|
|
17
17
|
|
|
18
18
|
$ pip3 install python_opendata_transport
|
|
19
19
|
|
|
20
|
+
On a Fedora-based system.
|
|
21
|
+
|
|
22
|
+
.. code:: bash
|
|
23
|
+
|
|
24
|
+
$ sudo dnf -y install python3-opendata-transport
|
|
25
|
+
|
|
20
26
|
Usage
|
|
21
27
|
-----
|
|
22
28
|
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"""Wrapper to get connection details from Opendata Transport."""
|
|
2
|
+
import asyncio
|
|
3
|
+
import logging
|
|
4
|
+
|
|
5
|
+
import aiohttp
|
|
6
|
+
import async_timeout
|
|
7
|
+
import urllib.parse
|
|
8
|
+
|
|
9
|
+
from . import exceptions
|
|
10
|
+
|
|
11
|
+
_LOGGER = logging.getLogger(__name__)
|
|
12
|
+
_RESOURCE_URL = "http://transport.opendata.ch/v1/"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class OpendataTransportBase(object):
|
|
16
|
+
"""Representation of the Opendata Transport base class"""
|
|
17
|
+
|
|
18
|
+
def __init__(self, loop, session):
|
|
19
|
+
self._loop = loop
|
|
20
|
+
self._session = session
|
|
21
|
+
|
|
22
|
+
@staticmethod
|
|
23
|
+
def get_url(resource, params):
|
|
24
|
+
"""Generate the URL for the request."""
|
|
25
|
+
param = urllib.parse.urlencode(params)
|
|
26
|
+
url = "{resource_url}{resource}?{param}".format(
|
|
27
|
+
resource_url=_RESOURCE_URL, resource=resource, param=param
|
|
28
|
+
)
|
|
29
|
+
return url
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class OpendataTransportStationboard(OpendataTransportBase):
|
|
33
|
+
"""A class for handling stationsboards from Opendata Transport."""
|
|
34
|
+
|
|
35
|
+
def __init__(self, station, loop, session, limit=5):
|
|
36
|
+
"""Initialize the journey."""
|
|
37
|
+
super().__init__(loop, session)
|
|
38
|
+
self.station = station
|
|
39
|
+
self.limit = limit
|
|
40
|
+
self.from_name = self.from_id = self.to_name = self.to_id = None
|
|
41
|
+
self.journeys = []
|
|
42
|
+
|
|
43
|
+
@staticmethod
|
|
44
|
+
def get_journey(journey):
|
|
45
|
+
"""Get the journey details."""
|
|
46
|
+
return {
|
|
47
|
+
"departure": journey["stop"]["departure"],
|
|
48
|
+
"delay": journey["stop"]["delay"],
|
|
49
|
+
"platform": journey["stop"]["platform"],
|
|
50
|
+
"name": journey["name"],
|
|
51
|
+
"category": journey["category"],
|
|
52
|
+
"number": journey["number"],
|
|
53
|
+
"to": journey["to"],
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async def __async_get_data(self, station):
|
|
57
|
+
"""Retrieve the data for the station."""
|
|
58
|
+
params = {"limit": self.limit}
|
|
59
|
+
if str.isdigit(station):
|
|
60
|
+
params["id"] = station
|
|
61
|
+
else:
|
|
62
|
+
params["station"] = station
|
|
63
|
+
|
|
64
|
+
url = self.get_url("stationboard", params)
|
|
65
|
+
|
|
66
|
+
try:
|
|
67
|
+
with async_timeout.timeout(5, loop=self._loop):
|
|
68
|
+
response = await self._session.get(url, raise_for_status=True)
|
|
69
|
+
|
|
70
|
+
_LOGGER.debug("Response from transport.opendata.ch: %s", response.status)
|
|
71
|
+
data = await response.json()
|
|
72
|
+
_LOGGER.debug(data)
|
|
73
|
+
except asyncio.TimeoutError:
|
|
74
|
+
_LOGGER.error("Can not load data from transport.opendata.ch")
|
|
75
|
+
raise exceptions.OpendataTransportConnectionError()
|
|
76
|
+
except aiohttp.ClientError as aiohttpClientError:
|
|
77
|
+
_LOGGER.error("Response from transport.opendata.ch: %s", aiohttpClientError)
|
|
78
|
+
raise exceptions.OpendataTransportConnectionError()
|
|
79
|
+
|
|
80
|
+
try:
|
|
81
|
+
for journey in data["stationboard"]:
|
|
82
|
+
self.journeys.append(self.get_journey(journey))
|
|
83
|
+
except (TypeError, IndexError):
|
|
84
|
+
raise exceptions.OpendataTransportError()
|
|
85
|
+
|
|
86
|
+
async def async_get_data(self):
|
|
87
|
+
"""Retrieve the data for the given station."""
|
|
88
|
+
if isinstance(self.station, list):
|
|
89
|
+
for station in self.station:
|
|
90
|
+
await self.__async_get_data(station)
|
|
91
|
+
list.sort(self.journeys, key=lambda journey: journey["departure"])
|
|
92
|
+
else:
|
|
93
|
+
await self.__async_get_data(self.station)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class OpendataTransport(OpendataTransportBase):
|
|
97
|
+
"""A class for handling connections from Opendata Transport."""
|
|
98
|
+
|
|
99
|
+
def __init__(self, start, destination, loop, session, limit=3):
|
|
100
|
+
"""Initialize the connection."""
|
|
101
|
+
super().__init__(loop, session)
|
|
102
|
+
self.limit = limit
|
|
103
|
+
self.start = start
|
|
104
|
+
self.destination = destination
|
|
105
|
+
self.from_name = self.from_id = self.to_name = self.to_id = None
|
|
106
|
+
self.connections = dict()
|
|
107
|
+
|
|
108
|
+
@staticmethod
|
|
109
|
+
def get_connection(connection):
|
|
110
|
+
"""Get the connection details."""
|
|
111
|
+
connection_info = dict()
|
|
112
|
+
connection_info["departure"] = connection["from"]["departure"]
|
|
113
|
+
connection_info["duration"] = connection["duration"]
|
|
114
|
+
connection_info["delay"] = connection["from"]["delay"]
|
|
115
|
+
connection_info["transfers"] = connection["transfers"]
|
|
116
|
+
|
|
117
|
+
# Sections journey can be null if there is a walking section at first
|
|
118
|
+
connection_info["number"] = ""
|
|
119
|
+
for section in connection["sections"]:
|
|
120
|
+
if section["journey"] is not None:
|
|
121
|
+
connection_info["number"] = section["journey"]["name"]
|
|
122
|
+
break
|
|
123
|
+
|
|
124
|
+
connection_info["platform"] = connection["from"]["platform"]
|
|
125
|
+
|
|
126
|
+
return connection_info
|
|
127
|
+
|
|
128
|
+
async def async_get_data(self):
|
|
129
|
+
"""Retrieve the data for the connection."""
|
|
130
|
+
url = self.get_url(
|
|
131
|
+
"connections",
|
|
132
|
+
{"from": self.start, "to": self.destination, "limit": self.limit},
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
try:
|
|
136
|
+
with async_timeout.timeout(5, loop=self._loop):
|
|
137
|
+
response = await self._session.get(url, raise_for_status=True)
|
|
138
|
+
|
|
139
|
+
_LOGGER.debug("Response from transport.opendata.ch: %s", response.status)
|
|
140
|
+
data = await response.json()
|
|
141
|
+
_LOGGER.debug(data)
|
|
142
|
+
except asyncio.TimeoutError:
|
|
143
|
+
_LOGGER.error("Can not load data from transport.opendata.ch")
|
|
144
|
+
raise exceptions.OpendataTransportConnectionError()
|
|
145
|
+
except aiohttp.ClientError as aiohttpClientError:
|
|
146
|
+
_LOGGER.error("Response from transport.opendata.ch: %s", aiohttpClientError)
|
|
147
|
+
raise exceptions.OpendataTransportConnectionError()
|
|
148
|
+
|
|
149
|
+
try:
|
|
150
|
+
self.from_id = data["from"]["id"]
|
|
151
|
+
self.from_name = data["from"]["name"]
|
|
152
|
+
self.to_id = data["to"]["id"]
|
|
153
|
+
self.to_name = data["to"]["name"]
|
|
154
|
+
index = 0
|
|
155
|
+
for connection in data["connections"]:
|
|
156
|
+
self.connections[index] = self.get_connection(connection)
|
|
157
|
+
index = index + 1
|
|
158
|
+
except (TypeError, IndexError):
|
|
159
|
+
raise exceptions.OpendataTransportError()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 1.1
|
|
2
2
|
Name: python-opendata-transport
|
|
3
|
-
Version: 0.1
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Python API for interacting with transport.opendata.ch.
|
|
5
5
|
Home-page: https://github.com/fabaff/python-opendata-transport
|
|
6
6
|
Author: Fabian Affolter
|
|
@@ -10,10 +10,10 @@ Download-URL: https://github.com/fabaff/python-opendata-transport/releases
|
|
|
10
10
|
Description: python-opendata-transport
|
|
11
11
|
=========================
|
|
12
12
|
|
|
13
|
-
Python
|
|
13
|
+
A Python client for interacting with `transport.opendata.ch <http://transport.opendata.ch/>`_.
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
is simply retrieving the details about a given connection between
|
|
15
|
+
This module is the base for the integration into `Home Assistant <https://home-assistant.io>`_
|
|
16
|
+
and is simply retrieving the details about a given connection between two stations.
|
|
17
17
|
|
|
18
18
|
This module is not official, developed, supported or endorsed by opendata.ch.
|
|
19
19
|
|
|
@@ -26,6 +26,12 @@ Description: python-opendata-transport
|
|
|
26
26
|
|
|
27
27
|
$ pip3 install python_opendata_transport
|
|
28
28
|
|
|
29
|
+
On a Fedora-based system.
|
|
30
|
+
|
|
31
|
+
.. code:: bash
|
|
32
|
+
|
|
33
|
+
$ sudo dnf -y install python3-opendata-transport
|
|
34
|
+
|
|
29
35
|
Usage
|
|
30
36
|
-----
|
|
31
37
|
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
3
|
-
Copyright (c) 2015-2018 Fabian Affolter <fabian@affolter-engineering.ch>
|
|
4
|
-
|
|
5
|
-
Licensed under MIT. All rights reserved.
|
|
6
|
-
"""
|
|
2
|
+
"""Setup for the Transport OpenData wrapper."""
|
|
7
3
|
import os
|
|
8
4
|
import sys
|
|
9
5
|
|
|
@@ -12,8 +8,8 @@ from setuptools import setup, find_packages
|
|
|
12
8
|
|
|
13
9
|
here = os.path.abspath(os.path.dirname(__file__))
|
|
14
10
|
|
|
15
|
-
with open(os.path.join(here, 'README.rst'), encoding='utf-8') as
|
|
16
|
-
long_description =
|
|
11
|
+
with open(os.path.join(here, 'README.rst'), encoding='utf-8') as readme:
|
|
12
|
+
long_description = readme.read()
|
|
17
13
|
|
|
18
14
|
if sys.argv[-1] == 'publish':
|
|
19
15
|
os.system('python3 setup.py sdist upload')
|
|
@@ -21,7 +17,7 @@ if sys.argv[-1] == 'publish':
|
|
|
21
17
|
|
|
22
18
|
setup(
|
|
23
19
|
name='python_opendata_transport',
|
|
24
|
-
version='0.1
|
|
20
|
+
version='0.2.1',
|
|
25
21
|
description='Python API for interacting with transport.opendata.ch.',
|
|
26
22
|
long_description=long_description,
|
|
27
23
|
url='https://github.com/fabaff/python-opendata-transport',
|
|
@@ -29,7 +25,7 @@ setup(
|
|
|
29
25
|
author='Fabian Affolter',
|
|
30
26
|
author_email='fabian@affolter-engineering.ch',
|
|
31
27
|
license='MIT',
|
|
32
|
-
install_requires=['aiohttp', 'async_timeout'],
|
|
28
|
+
install_requires=['aiohttp', 'async_timeout', 'urllib3'],
|
|
33
29
|
packages=find_packages(),
|
|
34
30
|
zip_safe=True,
|
|
35
31
|
classifiers=[
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Copyright (c) 2015-2018 Fabian Affolter <fabian@affolter-engineering.ch>
|
|
3
|
-
|
|
4
|
-
Licensed under MIT. All rights reserved.
|
|
5
|
-
"""
|
|
6
|
-
import asyncio
|
|
7
|
-
import logging
|
|
8
|
-
|
|
9
|
-
import aiohttp
|
|
10
|
-
import async_timeout
|
|
11
|
-
|
|
12
|
-
from . import exceptions
|
|
13
|
-
|
|
14
|
-
_LOGGER = logging.getLogger(__name__)
|
|
15
|
-
_RESOURCE = 'http://transport.opendata.ch/v1/'
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class OpendataTransport(object):
|
|
19
|
-
"""A class for handling connections from Opendata Transport."""
|
|
20
|
-
|
|
21
|
-
def __init__(self, start, destination, loop, session):
|
|
22
|
-
"""Initialize the connection."""
|
|
23
|
-
self._loop = loop
|
|
24
|
-
self._session = session
|
|
25
|
-
self.start = start
|
|
26
|
-
self.destination = destination
|
|
27
|
-
self.from_name = self.from_id = self.to_name = self.to_id = None
|
|
28
|
-
self.connections = dict()
|
|
29
|
-
|
|
30
|
-
async def async_get_data(self):
|
|
31
|
-
url = '{resource}connections?from={start}&to={dest}'.format(
|
|
32
|
-
resource=_RESOURCE, start=self.start, dest=self.destination)
|
|
33
|
-
|
|
34
|
-
try:
|
|
35
|
-
with async_timeout.timeout(5, loop=self._loop):
|
|
36
|
-
response = await self._session.get(url, raise_for_status=True)
|
|
37
|
-
|
|
38
|
-
_LOGGER.debug(
|
|
39
|
-
"Response from transport.opendata.ch: %s", response.status)
|
|
40
|
-
data = await response.json()
|
|
41
|
-
_LOGGER.debug(data)
|
|
42
|
-
except (asyncio.TimeoutError):
|
|
43
|
-
_LOGGER.error("Can not load data from transport.opendata.ch")
|
|
44
|
-
raise exceptions.OpendataTransportConnectionError()
|
|
45
|
-
except (aiohttp.ClientError) as aiohttpClientError:
|
|
46
|
-
_LOGGER.error("Response from transport.opendata.ch: %s",
|
|
47
|
-
aiohttpClientError)
|
|
48
|
-
raise exceptions.OpendataTransportConnectionError()
|
|
49
|
-
|
|
50
|
-
try:
|
|
51
|
-
self.from_id = data['from']['id']
|
|
52
|
-
self.from_name = data['from']['name']
|
|
53
|
-
self.to_id = data['to']['id']
|
|
54
|
-
self.to_name = data['to']['name']
|
|
55
|
-
index = 0
|
|
56
|
-
for conn in data['connections'][1:4]:
|
|
57
|
-
self.connections[index] = dict()
|
|
58
|
-
self.connections[index]['departure'] = \
|
|
59
|
-
conn['from']['departure']
|
|
60
|
-
self.connections[index]['duration'] = conn['duration']
|
|
61
|
-
self.connections[index]['transfers'] = conn['transfers']
|
|
62
|
-
self.connections[index]['number'] = \
|
|
63
|
-
conn['sections'][0]['journey']['name']
|
|
64
|
-
self.connections[index]['platform'] = conn['from']['platform']
|
|
65
|
-
index = index + 1
|
|
66
|
-
except (TypeError, IndexError):
|
|
67
|
-
raise exceptions.OpendataTransportError()
|
|
File without changes
|
{python_opendata_transport-0.1.4 → python_opendata_transport-0.2.1}/opendata_transport/exceptions.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|