python-opendata-transport 0.0.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.0.1/LICENSE +21 -0
- python_opendata_transport-0.0.1/MANIFEST.in +1 -0
- python_opendata_transport-0.0.1/PKG-INFO +11 -0
- python_opendata_transport-0.0.1/README.rst +38 -0
- python_opendata_transport-0.0.1/opendata_transport/__init__.py +50 -0
- python_opendata_transport-0.0.1/opendata_transport/exceptions.py +17 -0
- python_opendata_transport-0.0.1/python_opendata_transport.egg-info/PKG-INFO +11 -0
- python_opendata_transport-0.0.1/python_opendata_transport.egg-info/SOURCES.txt +13 -0
- python_opendata_transport-0.0.1/python_opendata_transport.egg-info/dependency_links.txt +1 -0
- python_opendata_transport-0.0.1/python_opendata_transport.egg-info/requires.txt +2 -0
- python_opendata_transport-0.0.1/python_opendata_transport.egg-info/top_level.txt +1 -0
- python_opendata_transport-0.0.1/python_opendata_transport.egg-info/zip-safe +1 -0
- python_opendata_transport-0.0.1/setup.cfg +7 -0
- python_opendata_transport-0.0.1/setup.py +27 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Fabian Affolter
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
include LICENSE
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 1.1
|
|
2
|
+
Name: python_opendata_transport
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Python API for interacting with transport.opendata.ch.
|
|
5
|
+
Home-page: https://github.com/fabaff/python-opendata-transport
|
|
6
|
+
Author: Fabian Affolter
|
|
7
|
+
Author-email: fabian@affolter-engineering.ch
|
|
8
|
+
License: MIT
|
|
9
|
+
Download-URL: https://github.com/fabaff/python-opendata-transport/releases
|
|
10
|
+
Description: UNKNOWN
|
|
11
|
+
Platform: UNKNOWN
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
python-opendata-transport
|
|
2
|
+
=========================
|
|
3
|
+
|
|
4
|
+
Python API for interacting with `transport.opendata.ch <http://transport.opendata.ch/>`_.
|
|
5
|
+
|
|
6
|
+
Installation
|
|
7
|
+
------------
|
|
8
|
+
The module is available from the `Python Package Index <https://pypi.python.org/pypi>`_.
|
|
9
|
+
|
|
10
|
+
.. code:: bash
|
|
11
|
+
|
|
12
|
+
$ pip3 install python_opendata_transport
|
|
13
|
+
|
|
14
|
+
Usage
|
|
15
|
+
-----
|
|
16
|
+
|
|
17
|
+
The file ``example.py`` contains a similar example.
|
|
18
|
+
|
|
19
|
+
.. code:: bash
|
|
20
|
+
|
|
21
|
+
>>> from opendata_transport import OpendataTransport
|
|
22
|
+
>>> data = OpendataTransport('Bern', 'Biel')
|
|
23
|
+
>>> data.get_data()
|
|
24
|
+
>>> print(data.connections)
|
|
25
|
+
|
|
26
|
+
Development
|
|
27
|
+
-----------
|
|
28
|
+
For development is recommanded to use a ``venv``.
|
|
29
|
+
|
|
30
|
+
.. code:: bash
|
|
31
|
+
|
|
32
|
+
$ python3.6 -m venv
|
|
33
|
+
$ source bin/activate
|
|
34
|
+
$ python3 setup.py develop
|
|
35
|
+
|
|
36
|
+
License
|
|
37
|
+
-------
|
|
38
|
+
``python-opendata-transport`` is licensed under MIT, for more details check LICENSE.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright (c) 2015-2017 Fabian Affolter <fabian@affolter-engineering.ch>
|
|
3
|
+
|
|
4
|
+
Licensed under MIT. All rights reserved.
|
|
5
|
+
"""
|
|
6
|
+
import requests
|
|
7
|
+
|
|
8
|
+
from . import exceptions
|
|
9
|
+
|
|
10
|
+
_RESOURCE = 'http://transport.opendata.ch/v1/'
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class OpendataTransport(object):
|
|
14
|
+
"""A class for handling connections from Opendata Transport."""
|
|
15
|
+
|
|
16
|
+
def __init__(self, start, destination):
|
|
17
|
+
"""Initialize the connection."""
|
|
18
|
+
self.start = start
|
|
19
|
+
self.destination = destination
|
|
20
|
+
self.from_name = self.from_id = self.to_name = self.to_id = None
|
|
21
|
+
self.connections = dict()
|
|
22
|
+
|
|
23
|
+
def get_data(self):
|
|
24
|
+
url = '{resource}connections?from={start}&to={dest}'.format(
|
|
25
|
+
resource=_RESOURCE, start=self.start, dest=self.destination)
|
|
26
|
+
response = requests.get(url, timeout=5)
|
|
27
|
+
|
|
28
|
+
if response.status_code != requests.codes.ok:
|
|
29
|
+
raise exceptions.OpendataTransportConnectionError()
|
|
30
|
+
|
|
31
|
+
data = response.json()
|
|
32
|
+
|
|
33
|
+
try:
|
|
34
|
+
self.from_id = data['from']['id']
|
|
35
|
+
self.from_name = data['from']['name']
|
|
36
|
+
self.to_id = data['to']['id']
|
|
37
|
+
self.to_name = data['to']['name']
|
|
38
|
+
index = 0
|
|
39
|
+
for conn in data['connections'][1:4]:
|
|
40
|
+
self.connections[index] = dict()
|
|
41
|
+
self.connections[index]['departure'] = \
|
|
42
|
+
conn['from']['departure']
|
|
43
|
+
self.connections[index]['duration'] = conn['duration']
|
|
44
|
+
self.connections[index]['transfers'] = conn['transfers']
|
|
45
|
+
self.connections[index]['number'] = \
|
|
46
|
+
conn['sections'][0]['journey']['name']
|
|
47
|
+
self.connections[index]['platform'] = conn['from']['platform']
|
|
48
|
+
index = index + 1
|
|
49
|
+
except IndexError:
|
|
50
|
+
raise exceptions.OpendataTransportError()
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright (c) 2015-2017 Fabian Affolter <fabian@affolter-engineering.ch>
|
|
3
|
+
|
|
4
|
+
Licensed under MIT. All rights reserved.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class OpendataTransportError(Exception):
|
|
9
|
+
"""General MyStromError exception occurred."""
|
|
10
|
+
|
|
11
|
+
pass
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class OpendataTransportConnectionError(OpendataTransportError):
|
|
15
|
+
"""When a connection error is encountered."""
|
|
16
|
+
|
|
17
|
+
pass
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 1.1
|
|
2
|
+
Name: python-opendata-transport
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Python API for interacting with transport.opendata.ch.
|
|
5
|
+
Home-page: https://github.com/fabaff/python-opendata-transport
|
|
6
|
+
Author: Fabian Affolter
|
|
7
|
+
Author-email: fabian@affolter-engineering.ch
|
|
8
|
+
License: MIT
|
|
9
|
+
Download-URL: https://github.com/fabaff/python-opendata-transport/releases
|
|
10
|
+
Description: UNKNOWN
|
|
11
|
+
Platform: UNKNOWN
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.rst
|
|
4
|
+
setup.cfg
|
|
5
|
+
setup.py
|
|
6
|
+
opendata_transport/__init__.py
|
|
7
|
+
opendata_transport/exceptions.py
|
|
8
|
+
python_opendata_transport.egg-info/PKG-INFO
|
|
9
|
+
python_opendata_transport.egg-info/SOURCES.txt
|
|
10
|
+
python_opendata_transport.egg-info/dependency_links.txt
|
|
11
|
+
python_opendata_transport.egg-info/requires.txt
|
|
12
|
+
python_opendata_transport.egg-info/top_level.txt
|
|
13
|
+
python_opendata_transport.egg-info/zip-safe
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
opendata_transport
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
from setuptools import setup
|
|
8
|
+
except ImportError:
|
|
9
|
+
from distutils.core import setup
|
|
10
|
+
|
|
11
|
+
if sys.argv[-1] == 'publish':
|
|
12
|
+
os.system('python3 setup.py sdist upload')
|
|
13
|
+
sys.exit()
|
|
14
|
+
|
|
15
|
+
setup(
|
|
16
|
+
name='python_opendata_transport',
|
|
17
|
+
version='0.0.1',
|
|
18
|
+
description='Python API for interacting with transport.opendata.ch.',
|
|
19
|
+
url='https://github.com/fabaff/python-opendata-transport',
|
|
20
|
+
download_url='https://github.com/fabaff/python-opendata-transport/releases',
|
|
21
|
+
author='Fabian Affolter',
|
|
22
|
+
author_email='fabian@affolter-engineering.ch',
|
|
23
|
+
license='MIT',
|
|
24
|
+
install_requires=['requests>=2.0', 'pytz'],
|
|
25
|
+
packages=['opendata_transport'],
|
|
26
|
+
zip_safe=True,
|
|
27
|
+
)
|