-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d75a3b4
Showing
6 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 Thomas Passer Jensen | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
## Installation | ||
|
||
```pip install rejseplanen``` | ||
|
||
## Module usage | ||
|
||
``` | ||
import rejseplanen | ||
print(rejseplanen.departureBoard(2158)) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from rejseplanen.methods import departureBoard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
""" | ||
Python implementation of communication with Rejseplanen API. | ||
More information about the API can be found at | ||
https://help.rejseplanen.dk/hc/en-us/articles/214174465-Rejseplanen-s-API | ||
""" | ||
|
||
from datetime import datetime | ||
import requests | ||
|
||
_RESOURCE = 'http://xmlopen.rejseplanen.dk/bin/rest.exe/' | ||
|
||
def departureBoard(stop_id, useTrain=None, useBus=None, useMetro=None, dateTime=None, offset=None, timeout=10): | ||
params = {} | ||
|
||
if type(stop_id) is int: | ||
params['id'] = stop_id | ||
else: | ||
raise TypeError("Expected <class 'int'>, got {}.".format(type(stop_id))) | ||
|
||
|
||
params['format'] = 'json' | ||
|
||
# API defaults to use all modes of transportation | ||
if useTrain is not None: | ||
if isinstance(useTrain, bool): | ||
params['useTog'] = int(useTrain) | ||
else: | ||
raise TypeError("Expected <class 'bool'>, got {}".format(type(useTrain))) | ||
if useBus is not None: | ||
if isinstance(useBus, bool): | ||
params['useBus'] = int(useBus) | ||
else: | ||
raise TypeError("Expected <class 'bool'>, got {}".format(type(useBus))) | ||
if useMetro is not None: | ||
if isinstance(useMetro, bool): | ||
params['useMetro'] = int(useMetro) | ||
else: | ||
raise TypeError("Expected <class 'bool'>, got {}".format(type(useMetro))) | ||
|
||
if dateTime and offset: | ||
raise ValueError('Cannot specify both time and offset') | ||
|
||
if dateTime: | ||
if isinstance(dateTime, datetime): | ||
params['date'] = dateTime.strftime("%d.%m.%y") | ||
params['time'] = dateTime.strftime("%H:%M") | ||
else: | ||
raise TypeError('Expected datetime.datime, got {}'.format(type(dateTime))) | ||
|
||
if offset: | ||
if isinstance(offset, int): | ||
params['offset'] = offset | ||
else: | ||
raise TypeError("Expected <class 'int'>, got {}".format(type(offset))) | ||
|
||
response = requests.get(_RESOURCE+'departureBoard', params, timeout=timeout) | ||
|
||
if response.status_code != 200: | ||
return response | ||
|
||
result = response.json()['DepartureBoard'] | ||
|
||
# This key is present on error | ||
if 'error' in result: | ||
return result | ||
|
||
return result['Departure'] | ||
|
||
if __name__ == "__main__": | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[metadata] | ||
description-file = README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from setuptools import setup | ||
setup( | ||
name = 'rejseplanen', # How you named your package folder (MyLib) | ||
packages = ['rejseplanen'], # Chose the same as "name" | ||
version = '0.1', # Start with a small number and increase it with every change you make | ||
license='MIT', # Chose a license from here: https://help.github.com/articles/licensing-a-repository | ||
description = 'Interface with Rejseplanen API', # Give a short description about your library | ||
author = 'Thomas Passer Jensen', # Type in your name | ||
author_email = 'tomatpasser@gmail.com', # Type in your E-Mail | ||
url = 'https://github.com/tomatpasser/python-rejseplanen', # Provide either the link to your github or to your website | ||
download_url = 'https://github.com/tomatpasser/python-rejseplanen/archive/v_01.tar.gz', # I explain this later on | ||
keywords = ['transport', 'rejseplanen', 'timetable', 'journey', 'public transport'], # Keywords that define your package best | ||
install_requires=[ # I get to this in a second | ||
'requests>=2.9.1', | ||
], | ||
classifiers=[ | ||
'Development Status :: 4 - Beta', # Chose either "3 - Alpha", "4 - Beta" or "5 - Production/Stable" as the current state of your package | ||
|
||
'Intended Audience :: Developers', # Define that your audience are developers | ||
'Topic :: Software Development :: Build Tools', | ||
|
||
'License :: OSI Approved :: MIT License', # Again, pick a license | ||
|
||
'Programming Language :: Python :: 3', #Specify which pyhton versions that you want to support | ||
'Programming Language :: Python :: 3.4', | ||
'Programming Language :: Python :: 3.5', | ||
'Programming Language :: Python :: 3.6', | ||
], | ||
) |