python-opendata-transport 0.0.1__tar.gz → 0.0.3__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 (17) hide show
  1. python_opendata_transport-0.0.3/PKG-INFO +20 -0
  2. {python_opendata_transport-0.0.1 → python_opendata_transport-0.0.3}/README.rst +3 -10
  3. {python_opendata_transport-0.0.1 → python_opendata_transport-0.0.3}/opendata_transport/__init__.py +22 -8
  4. {python_opendata_transport-0.0.1 → python_opendata_transport-0.0.3}/opendata_transport/exceptions.py +1 -1
  5. python_opendata_transport-0.0.3/python_opendata_transport.egg-info/PKG-INFO +20 -0
  6. python_opendata_transport-0.0.3/python_opendata_transport.egg-info/requires.txt +1 -0
  7. {python_opendata_transport-0.0.1 → python_opendata_transport-0.0.3}/setup.py +13 -2
  8. python_opendata_transport-0.0.1/PKG-INFO +0 -11
  9. python_opendata_transport-0.0.1/python_opendata_transport.egg-info/PKG-INFO +0 -11
  10. python_opendata_transport-0.0.1/python_opendata_transport.egg-info/requires.txt +0 -2
  11. {python_opendata_transport-0.0.1 → python_opendata_transport-0.0.3}/LICENSE +0 -0
  12. {python_opendata_transport-0.0.1 → python_opendata_transport-0.0.3}/MANIFEST.in +0 -0
  13. {python_opendata_transport-0.0.1 → python_opendata_transport-0.0.3}/python_opendata_transport.egg-info/SOURCES.txt +0 -0
  14. {python_opendata_transport-0.0.1 → python_opendata_transport-0.0.3}/python_opendata_transport.egg-info/dependency_links.txt +0 -0
  15. {python_opendata_transport-0.0.1 → python_opendata_transport-0.0.3}/python_opendata_transport.egg-info/top_level.txt +0 -0
  16. {python_opendata_transport-0.0.1 → python_opendata_transport-0.0.3}/python_opendata_transport.egg-info/zip-safe +0 -0
  17. {python_opendata_transport-0.0.1 → python_opendata_transport-0.0.3}/setup.cfg +0 -0
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 1.1
2
+ Name: python_opendata_transport
3
+ Version: 0.0.3
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
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: MacOS :: MacOS X
17
+ Classifier: Operating System :: Microsoft :: Windows
18
+ Classifier: Operating System :: POSIX
19
+ Classifier: Programming Language :: Python :: 3.4
20
+ Classifier: Topic :: Utilities
@@ -14,22 +14,15 @@ The module is available from the `Python Package Index <https://pypi.python.org/
14
14
  Usage
15
15
  -----
16
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)
17
+ The file ``example.py`` contains an example about how to use this module.
25
18
 
26
19
  Development
27
20
  -----------
28
- For development is recommanded to use a ``venv``.
21
+ For development is recommended to use a ``venv``.
29
22
 
30
23
  .. code:: bash
31
24
 
32
- $ python3.6 -m venv
25
+ $ python3.6 -m venv .
33
26
  $ source bin/activate
34
27
  $ python3 setup.py develop
35
28
 
@@ -3,32 +3,46 @@ Copyright (c) 2015-2017 Fabian Affolter <fabian@affolter-engineering.ch>
3
3
 
4
4
  Licensed under MIT. All rights reserved.
5
5
  """
6
- import requests
6
+ import asyncio
7
+ import logging
8
+
9
+ import aiohttp
10
+ import async_timeout
7
11
 
8
12
  from . import exceptions
9
13
 
14
+ _LOGGER = logging.getLogger(__name__)
10
15
  _RESOURCE = 'http://transport.opendata.ch/v1/'
11
16
 
12
17
 
13
18
  class OpendataTransport(object):
14
19
  """A class for handling connections from Opendata Transport."""
15
20
 
16
- def __init__(self, start, destination):
21
+ def __init__(self, start, destination, loop, session):
17
22
  """Initialize the connection."""
23
+ self._loop = loop
24
+ self._session = session
18
25
  self.start = start
19
26
  self.destination = destination
20
27
  self.from_name = self.from_id = self.to_name = self.to_id = None
21
28
  self.connections = dict()
22
29
 
23
- def get_data(self):
30
+ @asyncio.coroutine
31
+ def async_get_data(self):
24
32
  url = '{resource}connections?from={start}&to={dest}'.format(
25
33
  resource=_RESOURCE, start=self.start, dest=self.destination)
26
- response = requests.get(url, timeout=5)
27
34
 
28
- if response.status_code != requests.codes.ok:
29
- raise exceptions.OpendataTransportConnectionError()
35
+ try:
36
+ with async_timeout.timeout(5, loop=self._loop):
37
+ response = yield from self._session.get(url)
30
38
 
31
- data = response.json()
39
+ _LOGGER.debug(
40
+ "Response from transport.opendata.ch: %s", response.status)
41
+ data = yield from response.json()
42
+ _LOGGER.debug(data)
43
+ except (asyncio.TimeoutError, aiohttp.ClientError):
44
+ _LOGGER.error("Can not load data from transport.opendata.ch")
45
+ raise exceptions.OpendataTransportConnectionError()
32
46
 
33
47
  try:
34
48
  self.from_id = data['from']['id']
@@ -46,5 +60,5 @@ class OpendataTransport(object):
46
60
  conn['sections'][0]['journey']['name']
47
61
  self.connections[index]['platform'] = conn['from']['platform']
48
62
  index = index + 1
49
- except IndexError:
63
+ except (TypeError, IndexError):
50
64
  raise exceptions.OpendataTransportError()
@@ -6,7 +6,7 @@ Licensed under MIT. All rights reserved.
6
6
 
7
7
 
8
8
  class OpendataTransportError(Exception):
9
- """General MyStromError exception occurred."""
9
+ """General OpenDataError exception occurred."""
10
10
 
11
11
  pass
12
12
 
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 1.1
2
+ Name: python-opendata-transport
3
+ Version: 0.0.3
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
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: MacOS :: MacOS X
17
+ Classifier: Operating System :: Microsoft :: Windows
18
+ Classifier: Operating System :: POSIX
19
+ Classifier: Programming Language :: Python :: 3.4
20
+ Classifier: Topic :: Utilities
@@ -14,14 +14,25 @@ if sys.argv[-1] == 'publish':
14
14
 
15
15
  setup(
16
16
  name='python_opendata_transport',
17
- version='0.0.1',
17
+ version='0.0.3',
18
18
  description='Python API for interacting with transport.opendata.ch.',
19
19
  url='https://github.com/fabaff/python-opendata-transport',
20
20
  download_url='https://github.com/fabaff/python-opendata-transport/releases',
21
21
  author='Fabian Affolter',
22
22
  author_email='fabian@affolter-engineering.ch',
23
23
  license='MIT',
24
- install_requires=['requests>=2.0', 'pytz'],
24
+ install_requires=['aiohttp'],
25
25
  packages=['opendata_transport'],
26
26
  zip_safe=True,
27
+ classifiers=[
28
+ 'Development Status :: 3 - Alpha',
29
+ 'Environment :: Console',
30
+ 'Intended Audience :: Developers',
31
+ 'License :: OSI Approved :: MIT License',
32
+ 'Operating System :: MacOS :: MacOS X',
33
+ 'Operating System :: Microsoft :: Windows',
34
+ 'Operating System :: POSIX',
35
+ 'Programming Language :: Python :: 3.4',
36
+ 'Topic :: Utilities',
37
+ ],
27
38
  )
@@ -1,11 +0,0 @@
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
@@ -1,11 +0,0 @@
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