34 Commits

Author SHA1 Message Date
5690080a6a Version is set to 0.4.0-rc.1
Some checks reported warnings
Tests / test (3.11) (push) Has been cancelled
Tests / test (3.8) (push) Has been cancelled
Tests / test (3.9) (push) Has been cancelled
Tests / test (3.10) (push) Has been cancelled
2023-11-25 14:21:48 +01:00
f7873ac66b Fixed installation methods
Some checks reported warnings
Tests / test (3.11) (push) Has been cancelled
Tests / test (3.8) (push) Has been cancelled
Tests / test (3.9) (push) Has been cancelled
Tests / test (3.10) (push) Has been cancelled
2023-11-25 13:20:00 +01:00
83ae0999ea Documentation prepared and improved
Some checks reported warnings
Tests / test (3.11) (push) Has been cancelled
Tests / test (3.8) (push) Has been cancelled
Tests / test (3.9) (push) Has been cancelled
Tests / test (3.10) (push) Has been cancelled
2023-11-25 13:16:48 +01:00
3656a040f4 Okay, 1.0.0 was an overkill, module is in alpha
Some checks failed
Tests / test (3.10) (push) Failing after 22m55s
Tests / test (3.11) (push) Failing after 22m56s
Tests / test (3.9) (push) Has been cancelled
Tests / test (3.8) (push) Has been cancelled
2023-11-25 12:23:33 +01:00
414f3966da Attempt to temporarily fix #2
Some checks failed
Tests / test (3.10) (push) Failing after 23m0s
Tests / test (3.11) (push) Failing after 22m55s
Tests / test (3.8) (push) Failing after 22m56s
Tests / test (3.9) (push) Failing after 22m54s
2023-11-24 23:52:50 +01:00
efedb2533b WIP: Automatic tests
Some checks failed
Tests / test (3.10) (push) Failing after 18m31s
Tests / test (3.11) (push) Failing after 16m39s
Tests / test (3.8) (push) Failing after 1m15s
Tests / test (3.9) (push) Failing after 14m41s
2023-11-24 13:35:47 +01:00
059c511e05 Removed Client from classes
Some checks failed
Tests / test (3.10) (push) Failing after 5m26s
Tests / test (3.11) (push) Failing after 5m28s
Tests / test (3.8) (push) Failing after 5m25s
Tests / test (3.9) (push) Failing after 5m23s
2023-11-24 12:44:57 +01:00
c4b7197267 Classes restructure
Some checks failed
Tests / test (3.10) (push) Failing after 1m10s
Tests / test (3.11) (push) Failing after 1m7s
Tests / test (3.8) (push) Failing after 1m11s
Tests / test (3.9) (push) Has been cancelled
2023-11-24 12:39:25 +01:00
3a65991257 This commit breaks everything 2023-11-24 12:37:24 +01:00
7b9367c0a7 Changed imports 2023-11-24 12:35:51 +01:00
f31fa65d78 Small refactor and isort+black formatting
Some checks reported warnings
Tests / test (3.11) (push) Has been cancelled
Tests / test (3.8) (push) Has been cancelled
Tests / test (3.9) (push) Has been cancelled
Tests / test (3.10) (push) Has been cancelled
2023-11-24 11:21:02 +01:00
fa4f7b83ec Drop support for Python 3.7 (due to EOL)
Some checks failed
Tests / test (3.10) (push) Failing after 5m30s
Tests / test (3.11) (push) Failing after 5m33s
Tests / test (3.8) (push) Failing after 5m29s
Tests / test (3.9) (push) Failing after 5m29s
2023-11-19 23:47:41 +01:00
b0b874bfc8 env fix
Some checks failed
Tests / test (3.10) (push) Failing after 5m31s
Tests / test (3.11) (push) Failing after 5m34s
Tests / test (3.7) (push) Failing after 39s
Tests / test (3.8) (push) Failing after 5m53s
Tests / test (3.9) (push) Failing after 5m23s
2023-11-19 23:08:09 +01:00
9733557463 Added a few basic tests 2023-11-19 23:05:48 +01:00
9282578788 Structural changes
Some checks failed
Tests / test (3.10) (push) Failing after 1m10s
Tests / test (3.7) (push) Has been cancelled
Tests / test (3.8) (push) Has been cancelled
Tests / test (3.9) (push) Has been cancelled
Tests / test (3.11) (push) Has been cancelled
2023-11-19 22:38:51 +01:00
eb9a043c34 Probably a fix for #2 2023-11-19 12:19:31 +01:00
819bd5ff40 Add '.renovaterc' 2023-04-21 10:07:48 +03:00
c2e1fc54c1 Updated to 0.3.4 2023-01-04 11:55:06 +01:00
29ebb4627d Merge branch 'master' of https://git.profitroll.eu/profitroll/PythonRMV 2023-01-04 10:35:38 +01:00
6b6299cd0a Added one more check for correct response return 2023-01-04 10:35:33 +01:00
Profitroll
e91846edee Fixed empty boards return 2022-11-13 15:04:00 +01:00
Profitroll
9b6b2d6416 Updated meta to 0.3.3 2022-11-13 15:03:40 +01:00
Profitroll
f8b13ccedf Removed unused import 2022-10-12 17:42:42 +02:00
Profitroll
b47bc51365 Just a bit clarified docstring 2022-10-12 17:42:22 +02:00
Profitroll
f39da9b803 Updated meta to 0.3.2 2022-10-12 17:28:21 +02:00
Profitroll
1b863c55f1 Added retrieve_stops argument 2022-10-12 17:28:09 +02:00
Profitroll
80a788933d Improved README 2022-10-12 17:15:12 +02:00
Profitroll
3599a034dc Typing improved 2022-10-12 17:08:49 +02:00
Profitroll
e09e8f29fb Changed test function argument type 2022-10-08 12:27:13 +02:00
Profitroll
d23d9a005d Some errors ignored 2022-10-08 12:26:48 +02:00
9c9489aee1 Started writing wiki 2022-10-07 15:22:52 +02:00
07925d15eb Removed litter 2022-10-07 14:19:27 +02:00
a13027614e Updated meta to 0.3.1 2022-10-07 14:17:56 +02:00
ece22489ad Improved docs 2022-10-07 14:17:24 +02:00
98 changed files with 1692 additions and 1273 deletions

View File

@@ -0,0 +1,36 @@
name: Tests
on:
push:
branches:
- dev
- main
tags-ignore:
- v*
pull_request:
jobs:
test:
runs-on: ubuntu-latest
container: catthehacker/ubuntu:act-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
env:
AGENT_TOOLSDIRECTORY: /opt/hostedtoolcache
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Test with tox
env:
RMV_TOKEN: ${{ secrets.RMV_TOKEN }}
run: tox

15
.gitignore vendored
View File

@@ -154,12 +154,9 @@ cython_debug/
# Custom # Custom
.pypirc .vscode/
tests .venv_linux/
test.bat .venv_windows/
test_key.json
build.* # Module-related
cleanup.* tests/output/
publish.*
publish-release.*
.vscode

17
.renovaterc Normal file
View File

@@ -0,0 +1,17 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base"
],
"packageRules": [
{
"matchUpdateTypes": [
"minor",
"patch",
"pin",
"digest"
],
"automerge": true
}
]
}

View File

@@ -1,26 +1,31 @@
# PythonRMV <h1 align="center">PythonRMV</h1>
<p align="center">
<a href="https://git.end-play.xyz/profitroll/PythonRMV/src/branch/master/LICENSE"><img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-blue"></a>
<a href="https://git.end-play.xyz/profitroll/PythonRMV"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
</p>
Small module that makes your journey with RMV REST API somehow easier. Based fully on official RMV API reference and HAFAS documentation. Small module that makes your journey with RMV REST API somehow easier. Based fully on official RMV API reference and HAFAS documentation.
# Requirements ## Requirements
* RMV API key (Get it [here](https://opendata.rmv.de/site/start.html)) * RMV API key (Get it [here](https://opendata.rmv.de/site/start.html))
* Python3 (Tested versions are 3.7.9 and 3.9.13) * Python 3.8+
* git (Only for installation from source) * git (Only for installation from source)
# Installation ## Installation
If you have everything listed in [requirements](#requirements), then let's begin. If you have everything listed in [requirements](#requirements), then let's begin.
### Variant 1: ### Variant 1
1. `python -m pip install pyrmv`
### Variant 2: `python -m pip install pyrmv`
1. `git clone https://git.end-play.xyz/profitroll/PythonRMV.git`
2. `cd PythonRMV`
3. `python setup.py install`
# Usage ### Variant 2
`python -m pip install git+https://git.end-play.xyz/profitroll/PythonRMV.git`
## Usage
```py ```py
import pyrmv import pyrmv
@@ -32,48 +37,30 @@ client = pyrmv.Client("AcessId")
origin = client.stop_by_name("Frankfurt Hauptbahnhof", max_number=3)[0] origin = client.stop_by_name("Frankfurt Hauptbahnhof", max_number=3)[0]
destination = client.stop_by_coords(50.099613, 8.685449, max_number=3)[0] destination = client.stop_by_coords(50.099613, 8.685449, max_number=3)[0]
# Find a trip by locations got # Find a trip by locations you got above
trip = client.trip_find(origin_id=origin.id, dest_id=destination.id) trip = client.trip_find(origin_id=origin.id, dest_id=destination.id)
``` ```
# Frequently Asked Questions ## Frequently Asked Questions
- [Why are there raw versions and formatted ones?](#why-are-there-raw-versions-and-formatted-ones) * [Why are there raw versions and formatted ones?](#why-are-there-raw-versions-and-formatted-ones)
- [Some methods work slightly different](#some-methods-work-slightly-different) * [Some methods work slightly different](#some-methods-work-slightly-different)
## Why are there raw versions and formatted ones? ### Why are there raw versions and formatted ones?
For the purposes of my projects I don't really need all the stuff RMV gives (even though it's not much). For the purposes of my projects I don't really need all the stuff RMV gives (even though it's not much).
I only need some specific things. However I do understand that in some cases other users may find I only need some specific things. However I do understand that in some cases other users may find
those methods quite useful so I implemented them as well. those methods quite useful so I implemented them as well.
### Some methods work slightly different
## Some methods work slightly different
Can be. Not all function arguments written may work perfectly because I simply did not test each and Can be. Not all function arguments written may work perfectly because I simply did not test each and
every request. Some of arguments may be irrelevant in my use-case and the others are used quite rare at all. every request. Some of arguments may be irrelevant in my use-case and the others are used quite rare at all.
Just [make an issue](https://git.end-play.xyz/profitroll/PythonRMV/issues/new) and I'll implement it correct when I'll have some free time. Just [make an issue](https://git.end-play.xyz/profitroll/PythonRMV/issues/new) and I'll implement it correct when I'll have some free time.
# To-Do ## To-Do
## General
- [ ] Docs in Wiki
## Raw methods ### General
- [x] arrivalBoard (board_arrival)
- [x] departureBoard (board_departure)
- [x] himsearch (him_search)
- [x] journeyDetail (journey_detail)
- [x] location.nearbystops (stop_by_coords)
- [x] location.name (stop_by_name)
- [x] trip (trip_find)
- [x] recon (trip_recon)
## Normal methods * [ ] Docs in Wiki
- [x] arrivalBoard (board_arrival) * [ ] Tickets
- [x] departureBoard (board_departure)
- [x] himsearch (him_search)
- [x] journeyDetail (journey_detail)
- [x] location.nearbystops (stop_by_coords)
- [x] location.name (stop_by_name)
- [x] trip (trip_find)
- [x] recon (trip_recon)

69
pyproject.toml Normal file
View File

@@ -0,0 +1,69 @@
[build-system]
requires = ["setuptools>=52.0"]
build-backend = "setuptools.build_meta"
[project]
name = "pyrmv"
dynamic = ["version", "dependencies", "optional-dependencies"]
authors = [{ name = "Profitroll", email = "profitroll@end-play.xyz" }]
maintainers = [{ name = "Profitroll", email = "profitroll@end-play.xyz" }]
description = "Small module that makes your journey with RMV REST API somehow easier."
readme = "README.md"
requires-python = ">=3.8"
license = { text = "GPL3" }
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Utilities",
]
[project.urls]
Homepage = "https://git.end-play.xyz/profitroll/PythonRMV"
Source = "https://git.end-play.xyz/profitroll/PythonRMV"
Tracker = "https://git.end-play.xyz/profitroll/PythonRMV/issues"
Documentation = "https://git.end-play.xyz/profitroll/PythonRMV/wiki"
[tool.setuptools.dynamic]
version = { attr = "pyrmv.__version__" }
dependencies = { file = "requirements/_.txt" }
[tool.setuptools.dynamic.optional-dependencies]
dev = { file = "requirements/dev.txt" }
[tool.setuptools.packages.find]
where = ["src"]
[tool.black]
target-version = ['py38', 'py39', 'py310', 'py311']
line-length = 94
[tool.isort]
profile = "black"
[tool.pytest.ini_options]
minversion = "6.0"
python_files = ["test_*.py"]
pythonpath = "."
testpaths = ["tests"]
[tool.mypy]
namespace_packages = true
install_types = true
strict = true
show_error_codes = true
[tool.pylint.main]
extension-pkg-whitelist = ["ujson"]
py-version = 3.8
[tool.coverage.run]
source = ["pyrmv"]

View File

@@ -1,79 +0,0 @@
from datetime import datetime
from pyrmv.classes.Message import Message
class LineArrival():
def __init__(self, data, client):
self.journey = client.journey_detail(data["JourneyDetailRef"]["ref"])
self.status = data["JourneyStatus"]
self.messages = []
for message in data["Messages"]["Message"]:
self.messages.append(Message(message))
self.name = data["name"]
self.type = data["type"]
self.stop_name = data["stop"]
self.stop_id = data["stopid"]
self.stop_id_ext = data["stopExtId"]
self.stop = client.stop_by_id(self.stop_id)
self.time = datetime.strptime(data["time"], "%H:%M:%S")
self.date = datetime.strptime(data["date"], "%Y-%m-%d")
if ("rtTime" in data) and ("rtDate" in data):
self.time_real_time = datetime.strptime(data["rtTime"], "%H:%M:%S")
self.date_real_time = datetime.strptime(data["rtDate"], "%Y-%m-%d")
self.reachable = data["reachable"]
self.origin = data["origin"]
def __str__(self) -> str:
return f"{self.name} coming from {self.origin} at {self.time.time()} {self.date.date()}"
class LineDeparture():
def __init__(self, data, client):
self.journey = client.journey_detail(data["JourneyDetailRef"]["ref"])
self.status = data["JourneyStatus"]
self.messages = []
for message in data["Messages"]["Message"]:
self.messages.append(Message(message))
self.name = data["name"]
self.type = data["type"]
self.stop_name = data["stop"]
self.stop_id = data["stopid"]
self.stop_id_ext = data["stopExtId"]
self.stop = client.stop_by_id(self.stop_id)
self.time = datetime.strptime(data["time"], "%H:%M:%S")
self.date = datetime.strptime(data["date"], "%Y-%m-%d")
if ("rtTime" in data) and ("rtDate" in data):
self.time_real_time = datetime.strptime(data["rtTime"], "%H:%M:%S")
self.date_real_time = datetime.strptime(data["rtDate"], "%Y-%m-%d")
self.reachable = data["reachable"]
self.direction = data["direction"]
self.direction_flag = data["directionFlag"]
def __str__(self) -> str:
return f"{self.name} heading {self.direction} at {self.time.time()} {self.date.date()}"
class BoardArrival(list):
def __init__(self, data: dict, client):
super().__init__([])
for line in data["Arrival"]:
self.append(LineArrival(line, client))
def __str__(self) -> str:
lines = []
for line in self:
lines.append(str(line))
return "Arrival board\n" + "\n".join(lines)
class BoardDeparture(list):
def __init__(self, data: dict, client):
super().__init__([])
for line in data["Departure"]:
self.append(LineDeparture(line, client))
def __str__(self) -> str:
lines = []
for line in self:
lines.append(str(line))
return "Departure board\n" + "\n".join(lines)

View File

@@ -1,11 +0,0 @@
from isodate import parse_duration
class Gis():
"""Gis object."""
def __init__(self, ref: str, route: dict):
self.ref = ref
self.dist = route["dist"]
self.duration = parse_duration(route["durS"])
self.geo = route["dirGeo"]

View File

@@ -1,21 +0,0 @@
from pyrmv.classes.Stop import Stop
from pyrmv.classes.Message import Message
class Journey():
"""Journey object."""
def __init__(self, data: dict):
self.stops = []
self.ref = data["ref"]
self.direction = data["Directions"]["Direction"][0]["value"]
self.direction_flag = data["Directions"]["Direction"][0]["flag"]
self.messages = []
for stop in data["Stops"]["Stop"]:
self.stops.append(Stop(stop))
for message in data["Messages"]["Message"]:
self.messages.append(Message(message))
def __str__(self) -> str:
return f"Journey with total of {len(self.stops)} stops and {len(self.messages)} messages heading {self.direction} ({self.direction_flag})"

View File

@@ -1,43 +0,0 @@
from pyrmv.classes.Gis import Gis
from pyrmv.classes.Message import Message
from pyrmv.classes.Stop import StopTrip
from isodate import parse_duration
class Leg():
"""Trip leg object."""
def __init__(self, data: dict):
self.origin = StopTrip(data["Origin"])
self.destination = StopTrip(data["Destination"])
if "GisRef" in data:
self.gis = Gis(data["GisRef"]["ref"], data["GisRoute"])
else:
self.gis = None
self.index = data["idx"]
self.name = data["name"]
self.type = data["type"]
if "direction" in data:
self.direction = data["direction"]
else:
self.direction = None
self.messages = []
if "Messages" in data:
for message in data["Messages"]["Message"]:
self.messages.append(Message(message))
if "number" in data:
self.number = data["number"]
else:
self.number = None
self.duration = parse_duration(data["duration"])
if "dist" in data:
self.distance = data["dist"]
else:
self.distance = None

View File

@@ -1,54 +0,0 @@
from datetime import datetime
class Stop():
"""Stop object."""
def __init__(self, data: dict):
self.name = data["name"]
self.id = data["id"]
if "extId" in data:
self.ext_id = data["extId"]
else:
self.ext_id = None
if "description" in data:
self.description = data["description"]
else:
self.description = None
self.lon = data["lon"]
self.lat = data["lat"]
if "routeIdx" in data:
self.route_index = data["routeIdx"]
else:
self.route_index = None
if "arrTrack" in data:
self.track_arrival = data["arrTrack"]
else:
self.track_arrival = None
if "depTrack" in data:
self.track_departure = data["depTrack"]
else:
self.track_departure = None
def __str__(self) -> str:
return f"Stop {self.name} at {self.lon}, {self.lat}"
class StopTrip(Stop):
"""Trip stop object. It's like a Stop object, but with a date and time."""
def __init__(self, data: dict):
self.type = data["type"]
self.date = datetime.strptime(data["date"], "%Y-%m-%d")
self.time = datetime.strptime(data["time"], "%H:%M:%S")
super().__init__(data)
def __str__(self) -> str:
return f"Stop {self.name} at {self.lon}, {self.lat} at {self.time.time()} {self.date.date()}"

View File

@@ -1,9 +0,0 @@
from .Board import BoardArrival, BoardDeparture, LineArrival, LineDeparture
from .Gis import Gis
from .Journey import Journey
from .Leg import Leg
from .Message import Message, Channel, Url
from .Stop import Stop, StopTrip
from .Ticket import Ticket
from .Trip import Trip
from .Client import Client

View File

@@ -1,3 +0,0 @@
requests
xmltodict
isodate

3
requirements/_.txt Normal file
View File

@@ -0,0 +1,3 @@
requests~=2.31.0
xmltodict~=0.13.0
isodate~=0.6.1

12
requirements/dev.txt Normal file
View File

@@ -0,0 +1,12 @@
black==23.11.0
build==1.0.3
isort==5.12.0
mypy==1.7.0
pylint==3.0.2
pytest-asyncio==0.22.0
pytest-cov==4.1.0
pytest==7.4.3
tox==4.11.3
twine==4.0.2
types-aiofiles==23.2.0.0
types-ujson==5.8.0.1

View File

@@ -1,3 +0,0 @@
[metadata]
description_file=README.md
license_files=LICENSE

View File

@@ -1,40 +0,0 @@
from setuptools import setup
setup(
name="pyrmv",
version="0.3.0",
author="Profitroll",
description="Small module that makes your journey with RMV REST API somehow easier.",
long_description="Small module that makes your journey with RMV REST API somehow easier. Based fully on official RMV API reference and HAFAS documentation.\n\n# Usage\n\n```py\nimport pyrmv\n\n# Define a Client with API key\nclient = pyrmv.Client(\"AcessId\")\n\n# Get origin's and destination's location\norigin = client.stop_by_name(\"Frankfurt Hauptbahnhof\", max_number=3)[0]\ndestination = client.stop_by_coords(50.099613, 8.685449, max_number=3)[0]\n\n# Find a trip by locations got\ntrip = client.trip_find(origin_id=origin.id, dest_id=destination.id)\n```\n\n# Frequently Asked Questions\n\n- Why are there raw versions and formatted ones?\n- Some methods work slightly different\n\n## Why are there raw versions and formatted ones?\n\nFor the purposes of my projects I don't really need all the stuff RMV gives (even though it's not much).\nI only need some specific things. However I do understand that in some cases other users may find\nthose methods quite useful so I implemented them as well.\n\n\n## Some methods work slightly different\n\nCan be. Not all function arguments written may work perfectly because I simply did not test each and\nevery request. Some of arguments may be irrelevant in my use-case and the others are used quite rare at all.\nJust [make an issue](https://git.end-play.xyz/profitroll/PythonRMV/issues/new) and I'll implement it correct when I'll have some free time.\n\n# To-Do\n## General\n- [ ] Docs in Wiki\n\n## Raw methods\n- [x] arrivalBoard (board_arrival) \n- [x] departureBoard (board_departure) \n- [x] himsearch (him_search) \n- [x] journeyDetail (journey_detail)\n- [x] location.nearbystops (stop_by_coords) \n- [x] location.name (stop_by_name) \n- [x] trip (trip_find) \n- [x] recon (trip_recon)\n\n## Normal methods\n- [x] arrivalBoard (board_arrival) \n- [x] departureBoard (board_departure) \n- [x] himsearch (him_search) \n- [x] journeyDetail (journey_detail)\n- [x] location.nearbystops (stop_by_coords) \n- [x] location.name (stop_by_name) \n- [x] trip (trip_find) \n- [x] recon (trip_recon)",
long_description_content_type="text/markdown",
author_email="profitroll@end-play.xyz",
url="https://git.end-play.xyz/profitroll/PythonRMV",
project_urls={
"Bug Tracker": "https://git.end-play.xyz/profitroll/PythonRMV/issues",
"Documentation": "https://git.end-play.xyz/profitroll/PythonRMV/wiki",
"Source Code": "https://git.end-play.xyz/profitroll/PythonRMV.git",
},
packages=[
"pyrmv",
"pyrmv.raw",
"pyrmv.const",
"pyrmv.enums",
"pyrmv.errors",
"pyrmv.utility",
"pyrmv.classes"
],
install_requires=[
"requests",
"xmltodict",
"isodate"
],
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Utilities"
]
)

View File

@@ -21,15 +21,9 @@ trip = client.trip_find(origin_id=origin.id, dest_id=destination.id)
""" """
__name__ = "pyrmv" __name__ = "pyrmv"
__version__ = "0.3.0" __version__ = "0.4.0-rc.1"
__license__ = "MIT License" __license__ = "MIT License"
__author__ = "Profitroll" __author__ = "Profitroll"
from . import raw from . import classes, const, enums, errors, raw, utility
from . import const from .classes.client import Client
from . import enums
from . import errors
from . import utility
from .classes import *
from .classes.Client import Client
# from .methods import *

View File

@@ -0,0 +1,8 @@
from .board import BoardArrival, BoardDeparture, LineArrival, LineDeparture
from .gis import Gis
from .journey import Journey
from .leg import Leg
from .message import Channel, Message, Url
from .stop import Stop, StopTrip
from .ticket import Ticket
from .trip import Trip

106
src/pyrmv/classes/board.py Normal file
View File

@@ -0,0 +1,106 @@
from datetime import datetime
from typing import Any, Mapping
from pyrmv.classes.message import Message
from pyrmv.utility import ref_upgrade
class LineArrival:
def __init__(self, data: Mapping[str, Any], client, retrieve_stops: bool = True):
# Upgrade is temporarily used due to RMV API mismatch
# self.journey = client.journey_detail(data["JourneyDetailRef"]["ref"])
self.journey = client.journey_detail(ref_upgrade(data["JourneyDetailRef"]["ref"]))
self.status = data["JourneyStatus"]
self.messages = []
self.name = data["name"]
self.type = data["type"]
self.stop_name = data["stop"]
self.stop_id = data["stopid"]
self.stop_id_ext = data["stopExtId"]
self.stop = client.stop_by_id(self.stop_id) if retrieve_stops else None
self.stop = client.stop_by_id(self.stop_id)
self.time = datetime.strptime(data["time"], "%H:%M:%S")
self.date = datetime.strptime(data["date"], "%Y-%m-%d")
self.reachable = data["reachable"]
self.origin = data["origin"]
self.origin = data["origin"]
if "Messages" in data:
self.messages.extend(Message(message) for message in data["Messages"]["Message"])
if ("rtTime" in data) and ("rtDate" in data):
self.time_real_time = datetime.strptime(data["rtTime"], "%H:%M:%S")
self.date_real_time = datetime.strptime(data["rtDate"], "%Y-%m-%d")
else:
self.time_real_time = None
self.date_real_time = None
def __str__(self) -> str:
return (
f"{self.name} coming from {self.origin} at {self.time.time()} {self.date.date()}"
)
class LineDeparture:
def __init__(self, data: Mapping[str, Any], client, retrieve_stops: bool = True):
# Upgrade is temporarily used due to RMV API mismatch
# self.journey = client.journey_detail(data["JourneyDetailRef"]["ref"])
self.journey = client.journey_detail(ref_upgrade(data["JourneyDetailRef"]["ref"]))
self.status = data["JourneyStatus"]
self.messages = []
self.name = data["name"]
self.type = data["type"]
self.stop_name = data["stop"]
self.stop_id = data["stopid"]
self.stop_id_ext = data["stopExtId"]
self.stop = client.stop_by_id(self.stop_id) if retrieve_stops else None
self.time = datetime.strptime(data["time"], "%H:%M:%S")
self.date = datetime.strptime(data["date"], "%Y-%m-%d")
self.reachable = data["reachable"]
self.direction = data["direction"]
self.direction_flag = data["directionFlag"]
if "Messages" in data:
self.messages.extend(Message(message) for message in data["Messages"]["Message"])
if ("rtTime" in data) and ("rtDate" in data):
self.time_real_time = datetime.strptime(data["rtTime"], "%H:%M:%S")
self.date_real_time = datetime.strptime(data["rtDate"], "%Y-%m-%d")
else:
self.time_real_time = None
self.date_real_time = None
def __str__(self) -> str:
return (
f"{self.name} heading {self.direction} at {self.time.time()} {self.date.date()}"
)
class BoardArrival(list):
def __init__(self, data: Mapping[str, Any], client, retrieve_stops: bool = True):
super().__init__([])
if "Arrival" not in data:
return
for line in data["Arrival"]:
self.append(LineArrival(line, client, retrieve_stops=retrieve_stops))
def __str__(self) -> str:
return "Arrival board\n" + "\n".join([str(line) for line in self])
class BoardDeparture(list):
def __init__(self, data: Mapping[str, Any], client, retrieve_stops: bool = True):
super().__init__([])
if "Departure" not in data:
return
for line in data["Departure"]:
self.append(LineDeparture(line, client, retrieve_stops=retrieve_stops))
def __str__(self) -> str:
return "Departure board\n" + "\n".join([str(line) for line in self])

File diff suppressed because it is too large Load Diff

13
src/pyrmv/classes/gis.py Normal file
View File

@@ -0,0 +1,13 @@
from typing import Any, Mapping
from isodate import parse_duration
class Gis:
"""Gis object."""
def __init__(self, ref: str, route: Mapping[str, Any]):
self.ref = ref
self.dist = route["dist"]
self.duration = parse_duration(route["durS"])
self.geo = route["dirGeo"]

View File

@@ -0,0 +1,27 @@
from typing import Any, Mapping
from pyrmv.classes.message import Message
from pyrmv.classes.stop import Stop
from pyrmv.utility import ref_upgrade
class Journey:
"""Journey object."""
def __init__(self, data: Mapping[str, Any]):
self.stops = []
# Upgrade is temporarily used due to RMV API mismatch
# self.ref = data["ref"]
self.ref = ref_upgrade(data["ref"])
self.direction = data["Directions"]["Direction"][0]["value"]
self.direction_flag = data["Directions"]["Direction"][0]["flag"]
self.stops.extend(Stop(stop) for stop in data["Stops"]["Stop"])
self.messages = []
if "Messages" in data:
self.messages.extend(Message(message) for message in data["Messages"]["Message"])
def __str__(self) -> str:
return f"Journey with total of {len(self.stops)} stops and {len(self.messages)} messages heading {self.direction} ({self.direction_flag})"

29
src/pyrmv/classes/leg.py Normal file
View File

@@ -0,0 +1,29 @@
from typing import Any, Mapping
from isodate import parse_duration
from pyrmv.classes.gis import Gis
from pyrmv.classes.message import Message
from pyrmv.classes.stop import StopTrip
class Leg:
"""Trip leg object."""
def __init__(self, data: Mapping[str, Any]):
self.origin = StopTrip(data["Origin"])
self.destination = StopTrip(data["Destination"])
self.gis = (
None if "GisRef" not in data else Gis(data["GisRef"]["ref"], data["GisRoute"])
)
self.messages = []
self.index = data["idx"]
self.name = data["name"]
self.type = data["type"]
self.direction = data.get("direction")
self.number = data.get("number")
self.duration = parse_duration(data["duration"])
self.distance = data.get("dist")
if "Messages" in data:
self.messages.extend(Message(message) for message in data["Messages"]["Message"])

View File

@@ -1,25 +1,29 @@
from pyrmv.classes.Stop import Stop
from datetime import datetime from datetime import datetime
from typing import Any, Mapping
from isodate import parse_duration from isodate import parse_duration
class Url(): from pyrmv.classes.stop import Stop
"""Traffic message channel url object."""
def __init__(self, data: dict) -> None:
class Url:
"""Traffic message channel url object."""
def __init__(self, data: Mapping[str, Any]) -> None:
self.name = data["name"] self.name = data["name"]
self.url = data["url"] self.url = data["url"]
def __str__(self) -> str: def __str__(self) -> str:
return f"{self.name}: {self.url}" return f"{self.name}: {self.url}"
class Channel():
"""Traffic message channel object."""
def __init__(self, data: dict) -> None: class Channel:
"""Traffic message channel object."""
def __init__(self, data: Mapping[str, Any]) -> None:
self.name = data["name"] self.name = data["name"]
url = [] url = []
for link in url: url.extend(Url(link) for link in url)
url.append(Url(link))
self.url = url self.url = url
self.time_start = datetime.strptime(data["validFromTime"], "%H:%M:%S") self.time_start = datetime.strptime(data["validFromTime"], "%H:%M:%S")
self.date_start = datetime.strptime(data["validFromDate"], "%Y-%m-%d") self.date_start = datetime.strptime(data["validFromDate"], "%Y-%m-%d")
@@ -30,30 +34,17 @@ class Channel():
return f"{self.name}: from {self.time_start} {self.date_start} until {self.time_end} {self.date_end}" return f"{self.name}: from {self.time_start} {self.date_start} until {self.time_end} {self.date_end}"
class Message(): class Message:
"""Traffic message object.""" """Traffic message object."""
def __init__(self, data: dict) -> None:
def __init__(self, data: Mapping[str, Any]) -> None:
self.affected_stops = [] self.affected_stops = []
if "affectedStops" in data: self.valid_from_stop = (
for stop in data["affectedStops"]["StopLocation"]: None if "validFromStop" not in data else Stop(data["validFromStop"])
self.affected_stops.append(Stop(stop)) )
self.valid_to_stop = None if "validToStop" not in data else Stop(data["validToStop"])
if "validFromStop" in data:
self.valid_from_stop = Stop(data["validFromStop"])
else:
self.valid_from_stop = None
if "validToStop" in data:
self.valid_to_stop = Stop(data["validToStop"])
else:
self.valid_to_stop = None
self.channels = [] self.channels = []
for channel in data["channel"]: self.channels.extend(Channel(channel) for channel in data["channel"])
self.channels.append(Channel(channel))
self.id = data["id"] self.id = data["id"]
self.active = data["act"] self.active = data["act"]
self.head = data["head"] self.head = data["head"]
@@ -61,7 +52,7 @@ class Message():
self.text = data["text"] self.text = data["text"]
self.company = data["company"] self.company = data["company"]
self.category = data["category"] self.category = data["category"]
self.priority = data["priority"] self.priority = None if "priority" not in data else data["priority"]
self.products = data["products"] self.products = data["products"]
self.icon = data["icon"] self.icon = data["icon"]
self.time_start = datetime.strptime(data["sTime"], "%H:%M:%S") self.time_start = datetime.strptime(data["sTime"], "%H:%M:%S")
@@ -74,11 +65,12 @@ class Message():
self.date_modified = datetime.strptime(data["modDate"], "%Y-%m-%d") self.date_modified = datetime.strptime(data["modDate"], "%Y-%m-%d")
self.daily_start = datetime.strptime(data["dailyStartingAt"], "%H:%M:%S") self.daily_start = datetime.strptime(data["dailyStartingAt"], "%H:%M:%S")
self.daily_duration = parse_duration(data["dailyDuration"]) self.daily_duration = parse_duration(data["dailyDuration"])
self.base_type = data["baseType"] if "baseType" in data else None
if "baseType" in data: if "affectedStops" in data:
self.base_type = data["baseType"] self.affected_stops.extend(
else: Stop(stop) for stop in data["affectedStops"]["StopLocation"]
self.base_type = None )
def __str__(self) -> str: def __str__(self) -> str:
return f"{self.base_type} message with priority {self.products} valid from {self.time_start.time()} {self.date_start.date()} until {self.time_end.time()} {self.date_end.date()}: {self.head} - {self.lead}" return f"{self.base_type} message with priority {self.products} valid from {self.time_start.time()} {self.date_start.date()} until {self.time_end.time()} {self.date_end.date()}: {self.head} - {self.lead}"

32
src/pyrmv/classes/stop.py Normal file
View File

@@ -0,0 +1,32 @@
from datetime import datetime
class Stop:
"""Stop object."""
def __init__(self, data: dict):
self.name = data["name"]
self.id = data["id"]
self.ext_id = data.get("extId")
self.description = data.get("description")
self.lon = data["lon"]
self.lat = data["lat"]
self.route_index = data.get("routeIdx")
self.track_arrival = data.get("arrTrack")
self.track_departure = data.get("depTrack")
def __str__(self) -> str:
return f"Stop {self.name} at {self.lon}, {self.lat}"
class StopTrip(Stop):
"""Trip stop object. It's like a Stop object, but with a date and time."""
def __init__(self, data: dict):
self.type = data["type"]
self.date = datetime.strptime(data["date"], "%Y-%m-%d")
self.time = datetime.strptime(data["time"], "%H:%M:%S")
super().__init__(data)
def __str__(self) -> str:
return f"Stop {self.name} at {self.lon}, {self.lat} at {self.time.time()} {self.date.date()}"

View File

@@ -1,4 +1,4 @@
class Ticket(): class Ticket:
""" """
{ {
"externalContent": { "externalContent": {
@@ -44,9 +44,9 @@ class Ticket():
"FreigabeId": "20730", "FreigabeId": "20730",
"Freigabe":"2645, 3670, 5001, 5002, 5003, 5004, 5005, 5006, 5011, 5013, 5015, 5021, 5022, 5023, 5031, 5041, 5042, 5046, 5059, 5100, 5233, 6239, 6626, 6636, 6637, 6639, 6648, 6649, 6650, 6655, 6660, 6664, 6691", "Freigabe":"2645, 3670, 5001, 5002, 5003, 5004, 5005, 5006, 5011, 5013, 5015, 5021, 5022, 5023, 5031, 5041, 5042, 5046, 5059, 5100, 5233, 6239, 6626, 6636, 6637, 6639, 6648, 6649, 6650, 6655, 6660, 6664, 6691",
"FreigabeOverview": "Bad Homburg v.d.Höhe;Bad Soden a.Ts.;Eschborn;Friedrichsdorf;Glashütten" "FreigabeOverview": "Bad Homburg v.d.Höhe;Bad Soden a.Ts.;Eschborn;Friedrichsdorf;Glashütten"
} }
} }
""" """
def __init__(self) -> None: def __init__(self) -> None:
pass pass

View File

@@ -1,37 +1,28 @@
from pyrmv.classes.Leg import Leg
from pyrmv.classes.Stop import StopTrip
from isodate import parse_duration from isodate import parse_duration
class Trip(): from pyrmv.classes.leg import Leg
"""Trip object.""" from pyrmv.classes.stop import StopTrip
class Trip:
"""Trip object."""
def __init__(self, data: dict): def __init__(self, data: dict):
self.raw_data = data self.raw_data = data
self.origin = StopTrip(data["Origin"]) self.origin = StopTrip(data["Origin"])
self.destination = StopTrip(data["Destination"]) self.destination = StopTrip(data["Destination"])
self.legs = [] self.legs = []
for leg in data["LegList"]["Leg"]: self.legs.extend(Leg(leg) for leg in data["LegList"]["Leg"])
self.legs.append(Leg(leg))
self.calculation = data["calculation"] self.calculation = data["calculation"]
self.index = data["idx"] self.index = data["idx"]
self.id = data["tripId"] self.id = data["tripId"]
self.ctx_recon = data["ctxRecon"] self.ctx_recon = data["ctxRecon"]
self.duration = parse_duration(data["duration"]) self.duration = parse_duration(data["duration"])
self.real_time_duration = (
if "rtDuration" in data: None if "rtDuration" not in data else parse_duration(data["rtDuration"])
self.real_time_duration = parse_duration(data["rtDuration"]) )
else:
self.real_time_duration = None
self.checksum = data["checksum"] self.checksum = data["checksum"]
self.transfer_count = data.get("transferCount", 0)
if "transferCount" in data:
self.transfer_count = data["transferCount"]
else:
self.transfer_count = 0
def __str__(self) -> str: def __str__(self) -> str:
return f"Trip from {self.origin.name} to {self.destination.name} lasting {self.duration} ({self.real_time_duration}) with {len(self.legs)} legs and {self.transfer_count} transfers" return f"Trip from {self.origin.name} to {self.destination.name} lasting {self.duration} ({self.real_time_duration}) with {len(self.legs)} legs and {self.transfer_count} transfers"

View File

@@ -0,0 +1 @@
from .product import PRODUCTS

View File

@@ -17,4 +17,4 @@ PRODUCTS: Dict[str, int] = {
"ferry": 256, "ferry": 256,
"taxi": 512, "taxi": 512,
"bahn": 1024, "bahn": 1024,
} }

View File

@@ -1,10 +1,10 @@
from .product import Product from .aff_journey_mode import AffectedJourneyMode
from .rt_mode import RealTimeMode from .aff_journey_stop_mode import AffectedJourneyStopMode
from .board_type import BoardArrivalType, BoardDepartureType
from .filter_mode import FilterMode
from .lang import Language from .lang import Language
from .location_type import LocationType from .location_type import LocationType
from .selection_mode import SelectionMode from .product import Product
from .rt_mode import RealTimeMode
from .search_mode import SearchMode from .search_mode import SearchMode
from .filter_mode import FilterMode from .selection_mode import SelectionMode
from .board_type import BoardArrivalType, BoardDepartureType
from .aff_journey_mode import AffectedJourneyMode
from .aff_journey_stop_mode import AffectedJourneyStopMode

View File

@@ -1,6 +1,8 @@
from enum import auto from enum import auto
from .auto_name import AutoName from .auto_name import AutoName
class AffectedJourneyMode(AutoName): class AffectedJourneyMode(AutoName):
"""Enumeration used to declare types of HIM search modes.""" """Enumeration used to declare types of HIM search modes."""
@@ -8,4 +10,4 @@ class AffectedJourneyMode(AutoName):
"Return affected journeys." "Return affected journeys."
OFF = auto() OFF = auto()
"Do not return affected journeys." "Do not return affected journeys."

View File

@@ -1,6 +1,8 @@
from enum import auto from enum import auto
from .auto_name import AutoName from .auto_name import AutoName
class AffectedJourneyStopMode(AutoName): class AffectedJourneyStopMode(AutoName):
"""Enumeration used to declare types of affected journey stops return modes.""" """Enumeration used to declare types of affected journey stops return modes."""
@@ -11,4 +13,4 @@ class AffectedJourneyStopMode(AutoName):
"Return important stops of affected journeys." "Return important stops of affected journeys."
OFF = auto() OFF = auto()
"Do not return stops of affected journeys." "Do not return stops of affected journeys."

View File

@@ -2,7 +2,9 @@
# https://github.com/pyrogram/pyrogram/blob/master/pyrogram/enums/auto_name.py # https://github.com/pyrogram/pyrogram/blob/master/pyrogram/enums/auto_name.py
from enum import Enum from enum import Enum
from pyrmv.const.product import PRODUCTS
from pyrmv.const import PRODUCTS
class AutoName(Enum): class AutoName(Enum):
def __init__(self, code) -> None: def __init__(self, code) -> None:
@@ -14,6 +16,7 @@ class AutoName(Enum):
def __repr__(self): def __repr__(self):
return f"pyrmv.enums.{self}" return f"pyrmv.enums.{self}"
class AutoNameProduct(AutoName): class AutoNameProduct(AutoName):
def __init__(self, code) -> None: def __init__(self, code) -> None:
self.code = PRODUCTS[code] self.code = PRODUCTS[code]

View File

@@ -1,9 +1,11 @@
from enum import auto from enum import auto
from .auto_name import AutoName from .auto_name import AutoName
class BoardArrivalType(AutoName): class BoardArrivalType(AutoName):
"""Enumeration used to declare types of arrival board. """Enumeration used to declare types of arrival board.
* ARR - Arrival board as configured in HAFAS * ARR - Arrival board as configured in HAFAS
* ARR_EQUIVS - Arrival board with all journeys at any masts and equivalent stops * ARR_EQUIVS - Arrival board with all journeys at any masts and equivalent stops
* ARR_MAST - Arrival board at mast * ARR_MAST - Arrival board at mast
@@ -22,9 +24,10 @@ class BoardArrivalType(AutoName):
ARR_STATION = auto() ARR_STATION = auto()
"Arrival board with all journeys at any masts of the requested station" "Arrival board with all journeys at any masts of the requested station"
class BoardDepartureType(AutoName): class BoardDepartureType(AutoName):
"""Enumeration used to declare types of departure board. """Enumeration used to declare types of departure board.
* DEP - Departure board as configured in HAFAS * DEP - Departure board as configured in HAFAS
* DEP_EQUIVS - Departure board with all journeys at any masts and equivalent stops * DEP_EQUIVS - Departure board with all journeys at any masts and equivalent stops
* DEP_MAST - Departure board at mast * DEP_MAST - Departure board at mast
@@ -41,4 +44,4 @@ class BoardDepartureType(AutoName):
"Departure board at mast" "Departure board at mast"
DEP_STATION = auto() DEP_STATION = auto()
"Departure board with all journeys at any masts of the requested station" "Departure board with all journeys at any masts of the requested station"

View File

@@ -1,9 +1,11 @@
from enum import auto from enum import auto
from .auto_name import AutoName from .auto_name import AutoName
class FilterMode(AutoName): class FilterMode(AutoName):
"""Enumeration used to declare filters for nearby searches. """Enumeration used to declare filters for nearby searches.
* DIST_PERI - Accentuate matches. Matches in the radius are first * DIST_PERI - Accentuate matches. Matches in the radius are first
* EXCL_PERI - Returns matches inside the radius only * EXCL_PERI - Returns matches inside the radius only
* SLCT_PERI - Matches in the radius are excluded. Returns matches outside the radius only * SLCT_PERI - Matches in the radius are excluded. Returns matches outside the radius only
@@ -16,4 +18,4 @@ class FilterMode(AutoName):
"Returns matches inside the radius only." "Returns matches inside the radius only."
SLCT_PERI = auto() SLCT_PERI = auto()
"Matches in the radius are excluded. Returns matches outside the radius only." "Matches in the radius are excluded. Returns matches outside the radius only."

View File

@@ -1,24 +1,44 @@
from enum import auto from enum import auto
from .auto_name import AutoName from .auto_name import AutoName
class Language(AutoName): class Language(AutoName):
"""Enumeration used to declare locales as ISO-3166 codes (but only available in HAFAS ones).""" """Enumeration used to declare locales as ISO-3166 codes (but only available in HAFAS ones)."""
DE = auto() AR = auto()
"German" "Arabic"
CA = auto()
"Catalan, Valencian"
DA = auto() DA = auto()
"Danish" "Danish"
DE = auto()
"German"
EL = auto()
"Greek"
EN = auto() EN = auto()
"English" "English"
ES = auto() ES = auto()
"Spanish" "Spanish"
FI = auto()
"Finnish"
FR = auto() FR = auto()
"French" "French"
HI = auto()
"Hindi"
HR = auto()
"Croatian"
HU = auto() HU = auto()
"Hungarian" "Hungarian"
@@ -34,8 +54,26 @@ class Language(AutoName):
PL = auto() PL = auto()
"Polish" "Polish"
RU = auto()
"Russian"
SK = auto()
"Slovak"
SL = auto()
"Slovenian"
SV = auto() SV = auto()
"Swedish" "Swedish"
TL = auto()
"Tagalog"
TR = auto() TR = auto()
"Turkish" "Turkish"
UR = auto()
"Urdu"
ZH = auto()
"Chinese"

View File

@@ -1,9 +1,11 @@
from enum import auto from enum import auto
from .auto_name import AutoName from .auto_name import AutoName
class LocationType(AutoName): class LocationType(AutoName):
"""Enumeration used to declare types of location filter. """Enumeration used to declare types of location filter.
* S - Search for station/stops only * S - Search for station/stops only
* A - Search for addresses only * A - Search for addresses only
* P - Search for POIs only * P - Search for POIs only
@@ -15,7 +17,7 @@ class LocationType(AutoName):
* SPE - Search for stations/stops, POIs and entrypoints * SPE - Search for stations/stops, POIs and entrypoints
Note that not all location types may be available for a certain methods. Note that not all location types may be available for a certain methods.
Make sure that selected type is supported by method by looking up Make sure that selected type is supported by method by looking up
its acceptable types in argument description. its acceptable types in argument description.
""" """
@@ -44,4 +46,4 @@ class LocationType(AutoName):
"Search in all existing location pools" "Search in all existing location pools"
SPE = auto() SPE = auto()
"Search for stations/stops, POIs and entrypoints" "Search for stations/stops, POIs and entrypoints"

View File

@@ -1,6 +1,8 @@
from enum import auto from enum import auto
from .auto_name import AutoNameProduct from .auto_name import AutoNameProduct
class Product(AutoNameProduct): class Product(AutoNameProduct):
"""Enumeration used to declare types of transport.""" """Enumeration used to declare types of transport."""
@@ -11,7 +13,7 @@ class Product(AutoNameProduct):
"InterCity (commonly abbreviated IC on timetables and tickets) is the classification applied to certain long-distance passenger train services in Europe. Such trains (in contrast to regional, local, or commuter trains) generally call at major stations only." "InterCity (commonly abbreviated IC on timetables and tickets) is the classification applied to certain long-distance passenger train services in Europe. Such trains (in contrast to regional, local, or commuter trains) generally call at major stations only."
EC = auto() EC = auto()
"EuroCity, abbreviated as EC, is a cross-border train category within the European inter-city rail network. In contrast to trains allocated to the lower-level \"IC\" (InterCity) category, EC trains are international services that meet 20 criteria covering comfort, speed, food service, and cleanliness." 'EuroCity, abbreviated as EC, is a cross-border train category within the European inter-city rail network. In contrast to trains allocated to the lower-level "IC" (InterCity) category, EC trains are international services that meet 20 criteria covering comfort, speed, food service, and cleanliness.'
R = auto() R = auto()
"Regional rail, also known as local trains and stopping trains, are passenger rail services that operate between towns and cities. These trains operate with more stops over shorter distances than inter-city rail, but fewer stops and faster service than commuter rail." "Regional rail, also known as local trains and stopping trains, are passenger rail services that operate between towns and cities. These trains operate with more stops over shorter distances than inter-city rail, but fewer stops and faster service than commuter rail."
@@ -44,4 +46,4 @@ class Product(AutoNameProduct):
"A taxi, also known as a taxicab or simply a cab, is a type of vehicle for hire with a driver, used by a single passenger or small group of passengers, often for a non-shared ride." "A taxi, also known as a taxicab or simply a cab, is a type of vehicle for hire with a driver, used by a single passenger or small group of passengers, often for a non-shared ride."
BAHN = auto() BAHN = auto()
"Rail transport (also known as train transport) is a means of transport that transfers passengers and goods on wheeled vehicles running on rails, which are located on tracks. In contrast to road transport, where the vehicles run on a prepared flat surface, rail vehicles (rolling stock) are directionally guided by the tracks on which they run." "Rail transport (also known as train transport) is a means of transport that transfers passengers and goods on wheeled vehicles running on rails, which are located on tracks. In contrast to road transport, where the vehicles run on a prepared flat surface, rail vehicles (rolling stock) are directionally guided by the tracks on which they run."

View File

@@ -1,6 +1,8 @@
from enum import auto from enum import auto
from .auto_name import AutoName from .auto_name import AutoName
class RealTimeMode(AutoName): class RealTimeMode(AutoName):
"""Enumeration used to declare types of real-time traffic.""" """Enumeration used to declare types of real-time traffic."""
@@ -17,4 +19,4 @@ class RealTimeMode(AutoName):
"Search on real-time data: Connections are computed on the basis of real-time data, using planned schedule only whenever no real-time data is available. All connections computed are feasible with respect to the currently known real-time situation. Additional trains (supplied via real-time feed) will be found if these are part of a fast, comfortable, or direct connection (or economic connection, if economic search is activated)." "Search on real-time data: Connections are computed on the basis of real-time data, using planned schedule only whenever no real-time data is available. All connections computed are feasible with respect to the currently known real-time situation. Additional trains (supplied via real-time feed) will be found if these are part of a fast, comfortable, or direct connection (or economic connection, if economic search is activated)."
SERVER_DEFAULT = auto() SERVER_DEFAULT = auto()
"One of the other real-times modes used by default for RMV." "One of the other real-times modes used by default for RMV."

View File

@@ -1,6 +1,8 @@
from enum import auto from enum import auto
from .auto_name import AutoName from .auto_name import AutoName
class SearchMode(AutoName): class SearchMode(AutoName):
"""Enumeration used to declare types of HIM search modes.""" """Enumeration used to declare types of HIM search modes."""
@@ -11,4 +13,4 @@ class SearchMode(AutoName):
"Iterate over all HIM messages available." "Iterate over all HIM messages available."
TFMATCH = auto() TFMATCH = auto()
"Uses filters defined `metas` parameter." "Uses filters defined `metas` parameter."

View File

@@ -1,9 +1,11 @@
from enum import auto from enum import auto
from .auto_name import AutoName from .auto_name import AutoName
class SelectionMode(AutoName): class SelectionMode(AutoName):
"""Enumeration used to declare location selection modes. """Enumeration used to declare location selection modes.
* SLCT_A - Selectable * SLCT_A - Selectable
* SLCT_N - Not selectable * SLCT_N - Not selectable
""" """
@@ -12,4 +14,4 @@ class SelectionMode(AutoName):
"Selectable" "Selectable"
SLCT_N = auto() SLCT_N = auto()
"Not selectable" "Not selectable"

View File

@@ -0,0 +1,7 @@
from .api_errors import *
from .int_errors import *
from .not_ready import *
from .ps_errors import *
from .sot_errors import *
from .svc_errors import *
from .unknown_error import *

View File

@@ -2,32 +2,38 @@ class ApiAuthError(Exception):
""" """
Access denied for accessId provided. Access denied for accessId provided.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class ApiQuotaError(Exception): class ApiQuotaError(Exception):
""" """
Quota exceeded for accessId provided. Quota exceeded for accessId provided.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class ApiTooManyRequests(Exception): class ApiTooManyRequests(Exception):
""" """
Too many requests. Too many requests.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class ApiParamError(Exception): class ApiParamError(Exception):
"""Exception raised for errors in the input arguments. """Exception raised for errors in the input arguments.
@@ -42,14 +48,16 @@ class ApiParamError(Exception):
super().__init__(self.errorText) super().__init__(self.errorText)
def __str__(self): def __str__(self):
return f'{self.errorCode} -> {self.errorText}' return f"{self.errorCode} -> {self.errorText}"
class ApiFormatError(Exception): class ApiFormatError(Exception):
""" """
Response format not supported. Response format not supported.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__

View File

@@ -2,28 +2,33 @@ class IntError(Exception):
""" """
Internal RMV server error. Internal RMV server error.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class IntGatewayError(Exception): class IntGatewayError(Exception):
""" """
Communication error with RMV backend systems. Communication error with RMV backend systems.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class IntTimeoutError(Exception): class IntTimeoutError(Exception):
""" """
Timeout during service processing. Timeout during service processing.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__

View File

@@ -2,8 +2,9 @@ class NotReadyYetError(Exception):
""" """
This method is not finished yet. This method is not finished yet.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__

View File

@@ -6,8 +6,9 @@ class PsIncorrectParamError(Exception):
forward/backward from the end/beginning of the forward/backward from the end/beginning of the
connection. connection.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__

View File

@@ -2,48 +2,57 @@ class SotAlreadyArrivedError(Exception):
""" """
Trip already arrived. Trip already arrived.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SotNotStartedError(Exception): class SotNotStartedError(Exception):
""" """
Trip not started. Trip not started.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SotCancelledError(Exception): class SotCancelledError(Exception):
""" """
Trip cancelled. Trip cancelled.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SotAllTrainsFilteredError(Exception): class SotAllTrainsFilteredError(Exception):
""" """
All trips filtered. All trips filtered.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SotStayOnTripError(Exception): class SotStayOnTripError(Exception):
""" """
No change. Stay on trip. No change. Stay on trip.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__

View File

@@ -12,134 +12,160 @@ class SvcParamError(Exception):
super().__init__(self.errorText) super().__init__(self.errorText)
def __str__(self): def __str__(self):
return f'{self.errorCode} -> {self.errorText}' return f"{self.errorCode} -> {self.errorText}"
class SvcLocationError(Exception): class SvcLocationError(Exception):
""" """
Location missing or invalid. Location missing or invalid.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SvcLocationArrivalError(Exception): class SvcLocationArrivalError(Exception):
""" """
Arrival location missing or invalid. Arrival location missing or invalid.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SvcLocationDepartureError(Exception): class SvcLocationDepartureError(Exception):
""" """
Departure location missing or invalid. Departure location missing or invalid.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SvcLocationViaError(Exception): class SvcLocationViaError(Exception):
""" """
Unknown change stop. Unknown change stop.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SvcLocationEqualError(Exception): class SvcLocationEqualError(Exception):
""" """
Origin/destination or vias are equal. Origin/destination or vias are equal.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SvcLocationNearError(Exception): class SvcLocationNearError(Exception):
""" """
Origin and destination are too close. Origin and destination are too close.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SvcDatetimeError(Exception): class SvcDatetimeError(Exception):
""" """
Date/time are missing or invalid. Date/time are missing or invalid.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SvcDatetimePeriodError(Exception): class SvcDatetimePeriodError(Exception):
""" """
Date/time are not in timetable or allowed period. Date/time are not in timetable or allowed period.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SvcProductError(Exception): class SvcProductError(Exception):
""" """
Product field missing or invalid. Product field missing or invalid.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SvcContextError(Exception): class SvcContextError(Exception):
""" """
Context is invalid. Context is invalid.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SvcNoResultError(Exception): class SvcNoResultError(Exception):
""" """
No result found. No result found.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SvcSearchError(Exception): class SvcSearchError(Exception):
""" """
Unsuccessful search. Unsuccessful search.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SvcNoMatchError(Exception): class SvcNoMatchError(Exception):
""" """
No match found. No match found.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__

View File

@@ -12,4 +12,4 @@ class UnknownError(Exception):
super().__init__(self.errorText) super().__init__(self.errorText)
def __str__(self): def __str__(self):
return f'{self.errorCode} -> {self.errorText}' return f"{self.errorCode} -> {self.errorText}"

View File

@@ -5,4 +5,4 @@ from .journey_detail import journey_detail
from .stop_by_coords import stop_by_coords from .stop_by_coords import stop_by_coords
from .stop_by_name import stop_by_name from .stop_by_name import stop_by_name
from .trip_find import trip_find from .trip_find import trip_find
from .trip_recon import trip_recon from .trip_recon import trip_recon

View File

@@ -1,6 +1,7 @@
from requests import get
from datetime import datetime, timedelta from datetime import datetime, timedelta
from typing import Union from typing import Union
from requests import get
from xmltodict import parse as xmlparse from xmltodict import parse as xmlparse
try: try:
@@ -8,32 +9,34 @@ try:
except ImportError: except ImportError:
from typing_extensions import Literal from typing_extensions import Literal
# 2.25. Arrival Board (arrivalBoard) # 2.25. Arrival Board (arrivalBoard)
def board_arrival(accessId: str, def board_arrival(
json: bool = True, accessId: str,
id: str = None, # type: ignore json: bool = True,
extId: str = None, # type: ignore id: Union[str, None] = None,
direction: str = None, # type: ignore extId: Union[str, None] = None,
date: Union[str, datetime] = None, # type: ignore direction: Union[str, None] = None,
time: Union[str, datetime] = None, # type: ignore date: Union[str, datetime, None] = None,
duration: int = 60, time: Union[str, datetime, None] = None,
maxJourneys: int = -1, duration: Union[int, timedelta] = 60,
products: int = None, # type: ignore maxJourneys: int = -1,
operators: Union[str, list] = None, # type: ignore products: Union[int, None] = None,
lines: Union[str, list] = None, # type: ignore operators: Union[str, list, None] = None,
filterEquiv: bool = True, lines: Union[str, list, None] = None,
attributes: Union[str, list] = None, # type: ignore filterEquiv: bool = True,
platforms: Union[str, list] = None, # type: ignore attributes: Union[str, list, None] = None,
passlist: bool = False, platforms: Union[str, list, None] = None,
boardType: Literal["ARR", "ARR_EQUIVS", "ARR_MAST", "ARR_STATION"] = "ARR" passlist: bool = False,
) -> dict: boardType: Literal["ARR", "ARR_EQUIVS", "ARR_MAST", "ARR_STATION"] = "ARR",
) -> dict:
"""The arrival board can be retrieved by a call to the arrivalBoard service. This method will return the next """The arrival board can be retrieved by a call to the arrivalBoard service. This method will return the next
arrivals from a given point in time within a duration covered time span. The default duration size is 60 minutes. arrivals from a given point in time within a duration covered time span. The default duration size is 60 minutes.
Note: The result list always contains all arrivals running the the last minute found even if the requested Note: The result list always contains all arrivals running the the last minute found even if the requested
maximum was overrun. maximum was overrun.
Read more about this in section 2.25. "Arrival Board (arrivalBoard)" of HAFAS ReST Documentation. Read more about this in section 2.25. "Arrival Board (arrivalBoard)" of HAFAS ReST Documentation.
### Args: ### Args:
* accessId (str): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html). * accessId (str): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html).
@@ -56,14 +59,10 @@ def board_arrival(accessId: str,
### Returns: ### Returns:
* dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs. * dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs.
""" """
if json:
headers = {"Accept": "application/json"}
else:
headers = {"Accept": "application/xml"}
payload = {} payload = {}
headers = {"Accept": "application/json"} if json else {"Accept": "application/xml"}
for var, val in locals().items(): for var, val in locals().items():
if str(var) == "date": if str(var) == "date":
@@ -74,16 +73,12 @@ def board_arrival(accessId: str,
payload[str(var)] = val payload[str(var)] = val
elif str(var) == "time": elif str(var) == "time":
if val != None: if val != None:
if isinstance(val, datetime): payload[str(var)] = (
payload[str(var)] = val.strftime("%H:%M") val.strftime("%H:%M") if isinstance(val, datetime) else val
else: )
payload[str(var)] = val
elif str(var) == "duration": elif str(var) == "duration":
if val != None: if val != None:
if isinstance(val, timedelta): payload[str(var)] = val.minutes if isinstance(val, timedelta) else val
payload[str(var)] = val.minutes
else:
payload[str(var)] = val
elif str(var) == "boardType": elif str(var) == "boardType":
if val != None: if val != None:
payload["type"] = val.upper() payload["type"] = val.upper()
@@ -93,11 +88,4 @@ def board_arrival(accessId: str,
output = get("https://www.rmv.de/hapi/arrivalBoard", params=payload, headers=headers) output = get("https://www.rmv.de/hapi/arrivalBoard", params=payload, headers=headers)
# Exceptions checker moved to normal methods return output.json() if json else xmlparse(output.content)
# and exceptions will no longer raise in raw ones.
# find_exception(output.json())
if json:
return output.json()
else:
return xmlparse(output.content)

View File

@@ -1,6 +1,7 @@
from requests import get
from datetime import datetime, timedelta from datetime import datetime, timedelta
from typing import Union from typing import Union
from requests import get
from xmltodict import parse as xmlparse from xmltodict import parse as xmlparse
try: try:
@@ -8,33 +9,35 @@ try:
except ImportError: except ImportError:
from typing_extensions import Literal from typing_extensions import Literal
# 2.24. Departure Board (departureBoard) # 2.24. Departure Board (departureBoard)
def board_departure(accessId: str, def board_departure(
json: bool = True, accessId: str,
id: str = None, # type: ignore json: bool = True,
extId: str = None, # type: ignore id: Union[str, None] = None,
direction: str = None, # type: ignore extId: Union[str, None] = None,
date: Union[str, datetime] = None, # type: ignore direction: Union[str, None] = None,
time: Union[str, datetime] = None, # type: ignore date: Union[str, datetime, None] = None,
duration: int = 60, time: Union[str, datetime, None] = None,
maxJourneys: int = -1, duration: Union[int, timedelta] = 60,
products: int = None, # type: ignore maxJourneys: int = -1,
operators: Union[str, list] = None, # type: ignore products: Union[int, None] = None,
lines: Union[str, list] = None, # type: ignore operators: Union[str, list, None] = None,
filterEquiv: bool = True, lines: Union[str, list, None] = None,
attributes: Union[str, list] = None, # type: ignore filterEquiv: bool = True,
platforms: Union[str, list] = None, # type: ignore attributes: Union[str, list, None] = None,
passlist: bool = False, platforms: Union[str, list, None] = None,
boardType: Literal["DEP", "DEP_EQUIVS", "DEP_MAST", "DEP_STATION"] = "DEP" passlist: bool = False,
) -> dict: boardType: Literal["DEP", "DEP_EQUIVS", "DEP_MAST", "DEP_STATION"] = "DEP",
) -> dict:
"""The separture board can be retrieved by a call to the departureBoard service. This method will return the """The separture board can be retrieved by a call to the departureBoard service. This method will return the
next departures (or less if not existing) from a given point in time within a duration covered time span. The next departures (or less if not existing) from a given point in time within a duration covered time span. The
default duration size is 60 minutes. default duration size is 60 minutes.
Note: The result list always contains all departures running the the last minute found even if the requested Note: The result list always contains all departures running the the last minute found even if the requested
maximum was overrun. maximum was overrun.
Read more about this in section 2.24. "Departure Board (departureBoard)" of HAFAS ReST Documentation. Read more about this in section 2.24. "Departure Board (departureBoard)" of HAFAS ReST Documentation.
### Args: ### Args:
* accessId (str): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html). * accessId (str): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html).
@@ -57,14 +60,10 @@ def board_departure(accessId: str,
### Returns: ### Returns:
* dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs. * dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs.
""" """
if json:
headers = {"Accept": "application/json"}
else:
headers = {"Accept": "application/xml"}
payload = {} payload = {}
headers = {"Accept": "application/json"} if json else {"Accept": "application/xml"}
for var, val in locals().items(): for var, val in locals().items():
if str(var) == "date": if str(var) == "date":
@@ -75,16 +74,12 @@ def board_departure(accessId: str,
payload[str(var)] = val payload[str(var)] = val
elif str(var) == "time": elif str(var) == "time":
if val != None: if val != None:
if isinstance(val, datetime): payload[str(var)] = (
payload[str(var)] = val.strftime("%H:%M") val.strftime("%H:%M") if isinstance(val, datetime) else val
else: )
payload[str(var)] = val
elif str(var) == "duration": elif str(var) == "duration":
if val != None: if val != None:
if isinstance(val, timedelta): payload[str(var)] = val.minutes if isinstance(val, timedelta) else val
payload[str(var)] = val.minutes
else:
payload[str(var)] = val
elif str(var) == "boardType": elif str(var) == "boardType":
if val != None: if val != None:
payload["type"] = val.upper() payload["type"] = val.upper()
@@ -94,11 +89,4 @@ def board_departure(accessId: str,
output = get("https://www.rmv.de/hapi/departureBoard", params=payload, headers=headers) output = get("https://www.rmv.de/hapi/departureBoard", params=payload, headers=headers)
# Exceptions checker moved to normal methods return output.json() if json else xmlparse(output.content)
# and exceptions will no longer raise in raw ones.
# find_exception(output.json())
if json:
return output.json()
else:
return xmlparse(output.content)

View File

@@ -1,55 +1,58 @@
from requests import get
from typing import OrderedDict, Union
from xmltodict import parse as xmlparse
from datetime import datetime from datetime import datetime
from typing import OrderedDict, Union
from pyrmv.utility.weekdays_bitmask import weekdays_bitmask from requests import get
from xmltodict import parse as xmlparse
from pyrmv.utility import weekdays_bitmask
try: try:
from typing import Literal from typing import Literal
except ImportError: except ImportError:
from typing_extensions import Literal from typing_extensions import Literal
# 2.37. HIM Search (himsearch) # 2.37. HIM Search (himsearch)
def him_search(accessId: str, def him_search(
json: bool = True, accessId: str,
dateB: Union[str, datetime] = None, # type: ignore json: bool = True,
dateE: Union[str, datetime] = None, # type: ignore dateB: Union[str, datetime, None] = None,
timeB: Union[str, datetime] = None, # type: ignore dateE: Union[str, datetime, None] = None,
timeE: Union[str, datetime] = None, # type: ignore timeB: Union[str, datetime, None] = None,
weekdays: Union[str, OrderedDict[str, bool]] = None, # type: ignore timeE: Union[str, datetime, None] = None,
himIds: Union[str, list] = None, # type: ignore weekdays: Union[str, OrderedDict[str, bool], None] = None,
hierarchicalView: bool = False, himIds: Union[str, list, None] = None,
operators: Union[str, list] = None, # type: ignore hierarchicalView: bool = False,
categories: Union[str, list] = None, # type: ignore operators: Union[str, list, None] = None,
channels: Union[str, list] = None, # type: ignore categories: Union[str, list, None] = None,
companies: Union[str, list] = None, # type: ignore channels: Union[str, list, None] = None,
lines: Union[str, list] = None, # type: ignore companies: Union[str, list, None] = None,
lineids: Union[str, list] = None, # type: ignore lines: Union[str, list, None] = None,
stations: Union[str, list] = None, # type: ignore lineids: Union[str, list, None] = None,
fromstation: str = None, # type: ignore stations: Union[str, list, None] = None,
tostation: str = None, # type: ignore fromstation: Union[str, None] = None,
bothways: bool = None, # type: ignore tostation: Union[str, None] = None,
trainnames: Union[str, list] = None, # type: ignore bothways: Union[bool, None] = None,
metas: Union[str, list] = None, # type: ignore trainnames: Union[str, list, None] = None,
himcategory: str = None, # type: ignore metas: Union[str, list, None] = None,
himtags: Union[str, list] = None, # type: ignore himcategory: Union[str, None] = None,
regions: Union[str, list] = None, # type: ignore himtags: Union[str, list, None] = None,
himtext: Union[str, list] = None, # type: ignore regions: Union[str, list, None] = None,
himtexttags: Union[str, list] = None, # type: ignore himtext: Union[str, list, None] = None,
additionalfields: Union[str, list, dict] = None, # type: ignore himtexttags: Union[str, list, None] = None,
poly: bool = False, additionalfields: Union[str, list, dict, None] = None,
searchmode: Literal["MATCH", "NOMATCH", "TFMATCH"] = None, # type: ignore poly: bool = False,
affectedJourneyMode: Literal["ALL", "OFF"] = None, # type: ignore searchmode: Union[Literal["MATCH", "NOMATCH", "TFMATCH"], None] = None,
affectedJourneyStopMode: Literal["ALL", "IMP", "OFF"] = None, # type: ignore affectedJourneyMode: Union[Literal["ALL", "OFF"], None] = None,
orderBy: Union[str, list] = None, # type: ignore affectedJourneyStopMode: Union[Literal["ALL", "IMP", "OFF"], None] = None,
minprio: Union[str, int] = None, # type: ignore orderBy: Union[str, list, None] = None,
maxprio: Union[str, int] = None # type: ignore minprio: Union[str, int, None] = None,
) -> dict: maxprio: Union[str, int, None] = None,
) -> dict:
"""The himSearch will return a list of HIM messages if matched by the given criteria as well as affected """The himSearch will return a list of HIM messages if matched by the given criteria as well as affected
products if any. products if any.
Read more about this in section 2.37. "HIM Search (himsearch)" of HAFAS ReST Documentation. Read more about this in section 2.37. "HIM Search (himsearch)" of HAFAS ReST Documentation.
### Args: ### Args:
* accessId (str): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html). * accessId (str): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html).
@@ -89,28 +92,23 @@ def him_search(accessId: str,
### Returns: ### Returns:
* dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs. * dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs.
""" """
if json:
headers = {"Accept": "application/json"}
else:
headers = {"Accept": "application/xml"}
payload = {} payload = {}
headers = {"Accept": "application/json"} if json else {"Accept": "application/xml"}
for var, val in locals().items(): for var, val in locals().items():
if str(var) in ["dateB", "dateE"]: if str(var) in {"dateB", "dateE"}:
if val != None: if val != None:
if isinstance(val, datetime): if isinstance(val, datetime):
payload[str(var)] = val.strftime("%Y-%m-%d") payload[str(var)] = val.strftime("%Y-%m-%d")
else: else:
payload[str(var)] = val payload[str(var)] = val
elif str(var) in ["timeB", "timeE"]: elif str(var) in {"timeB", "timeE"}:
if val != None: if val != None:
if isinstance(val, datetime): payload[str(var)] = (
payload[str(var)] = val.strftime("%H:%M") val.strftime("%H:%M") if isinstance(val, datetime) else val
else: )
payload[str(var)] = val
elif str(var) == "weekdays": elif str(var) == "weekdays":
if val != None: if val != None:
if isinstance(val, OrderedDict): if isinstance(val, OrderedDict):
@@ -132,11 +130,4 @@ def him_search(accessId: str,
output = get("https://www.rmv.de/hapi/himsearch", params=payload, headers=headers) output = get("https://www.rmv.de/hapi/himsearch", params=payload, headers=headers)
# Exceptions checker moved to normal methods return output.json() if json else xmlparse(output.content)
# and exceptions will no longer raise in raw ones.
# find_exception(output.json())
if json:
return output.json()
else:
return xmlparse(output.content)

View File

@@ -1,6 +1,7 @@
from datetime import datetime from datetime import datetime
from requests import get
from typing import Union from typing import Union
from requests import get
from xmltodict import parse as xmlparse from xmltodict import parse as xmlparse
try: try:
@@ -8,27 +9,29 @@ try:
except ImportError: except ImportError:
from typing_extensions import Literal from typing_extensions import Literal
# 2.26. Journey Detail (journeyDetail) # 2.26. Journey Detail (journeyDetail)
def journey_detail(accessId: str, def journey_detail(
id: str, accessId: str,
json: bool = True, id: str,
date: Union[str, datetime] = None, # type: ignore json: bool = True,
poly: bool = False, date: Union[str, datetime, None] = None,
polyEnc: Literal["DLT", "GPA", "N"] = "N", poly: bool = False,
showPassingPoints: bool = False, polyEnc: Literal["DLT", "GPA", "N"] = "N",
rtMode: Literal["FULL", "INFOS", "OFF", "REALTIME", "SERVER_DEFAULT"] = None, # type: ignore showPassingPoints: bool = False,
fromId: str = None, # type: ignore rtMode: Union[Literal["FULL", "INFOS", "OFF", "REALTIME", "SERVER_DEFAULT"], None] = None,
fromIdx: str = None, # type: ignore fromId: Union[str, None] = None,
toId: str = None, # type: ignore fromIdx: Union[int, None] = None,
toIdx: str = None, # type: ignore toId: Union[str, None] = None,
baim: bool = False toIdx: Union[int, None] = None,
) -> dict: baim: bool = False,
) -> dict:
"""The journey_detail method will deliver information about the complete route of a vehicle. The journey """The journey_detail method will deliver information about the complete route of a vehicle. The journey
identifier is part of a trip or departureBoard response. It contains a list of all stops/stations of this journey identifier is part of a trip or departureBoard response. It contains a list of all stops/stations of this journey
including all departure and arrival times (with real-time data if available) and additional information like including all departure and arrival times (with real-time data if available) and additional information like
specific attributes about facilities and other texts. specific attributes about facilities and other texts.
Read more about this in section 2.26. "Journey Detail (journeyDetail)" of HAFAS ReST Documentation. Read more about this in section 2.26. "Journey Detail (journeyDetail)" of HAFAS ReST Documentation.
### Args: ### Args:
* accessId (str): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html). * accessId (str): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html).
@@ -47,14 +50,10 @@ def journey_detail(accessId: str,
### Returns: ### Returns:
* dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs. * dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs.
""" """
if json:
headers = {"Accept": "application/json"}
else:
headers = {"Accept": "application/xml"}
payload = {} payload = {}
headers = {"Accept": "application/json"} if json else {"Accept": "application/xml"}
for var, val in locals().items(): for var, val in locals().items():
if str(var) == "rtMode": if str(var) == "rtMode":
@@ -66,11 +65,4 @@ def journey_detail(accessId: str,
output = get("https://www.rmv.de/hapi/journeyDetail", params=payload, headers=headers) output = get("https://www.rmv.de/hapi/journeyDetail", params=payload, headers=headers)
# Exceptions checker moved to normal methods return output.json() if json else xmlparse(output.content)
# and exceptions will no longer raise in raw ones.
# find_exception(output.json())
if json:
return output.json()
else:
return xmlparse(output.content)

View File

@@ -1,5 +1,6 @@
from requests import get
from typing import Union from typing import Union
from requests import get
from xmltodict import parse as xmlparse from xmltodict import parse as xmlparse
try: try:
@@ -7,25 +8,29 @@ try:
except ImportError: except ImportError:
from typing_extensions import Literal from typing_extensions import Literal
# 2.4. Location Search by Coordinate (location.nearbystops)
def stop_by_coords(accessId: str,
originCoordLat: Union[str, float],
originCoordLong: Union[str, float],
lang: Literal["de", "da", "en", "es", "fr", "hu", "it", "nl", "no", "pl", "sv", "tr"] = "en",
json: bool = True,
radius: Union[int, float] = 1000,
maxNo: int = 10,
stopType: Literal["S", "P", "SP", "SE", "SPE"] = "S",
locationSelectionMode: Literal["SLCT_N", "SLCT_A"] = None, # type: ignore
products: int = None, # type: ignore
meta: str = None, # type: ignore
sattributes: Union[str, list] = None, # type: ignore
sinfotexts: Union[str, list] = None # type: ignore
) -> dict:
"""The location.nearbystops service returns a list of stops around a given center coordinate (within a
radius of 1000m). The returned results are ordered by their distance to the center coordinate.
Read more about this in section 2.4. "Location Search by Coordinate (location.nearbystops)" of HAFAS ReST Documentation. # 2.4. Location Search by Coordinate (location.nearbystops)
def stop_by_coords(
accessId: str,
originCoordLat: Union[str, float],
originCoordLong: Union[str, float],
lang: Literal[
"de", "da", "en", "es", "fr", "hu", "it", "nl", "no", "pl", "sv", "tr"
] = "en",
json: bool = True,
radius: Union[int, float] = 1000,
maxNo: int = 10,
stopType: Literal["S", "P", "SP", "SE", "SPE"] = "S",
locationSelectionMode: Union[Literal["SLCT_N", "SLCT_A"], None] = None,
products: Union[int, None] = None,
meta: Union[str, None] = None,
sattributes: Union[str, list, None] = None,
sinfotexts: Union[str, list, None] = None,
) -> dict:
"""The location.nearbystops service returns a list of stops around a given center coordinate (within a
radius of 1000m). The returned results are ordered by their distance to the center coordinate.
Read more about this in section 2.4. "Location Search by Coordinate (location.nearbystops)" of HAFAS ReST Documentation.
### Args: ### Args:
* accessId (str): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html). * accessId (str): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html).
@@ -44,14 +49,10 @@ def stop_by_coords(accessId: str,
### Returns: ### Returns:
* dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs. * dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs.
""" """
if json:
headers = {"Accept": "application/json"}
else:
headers = {"Accept": "application/xml"}
payload = {} payload = {}
headers = {"Accept": "application/json"} if json else {"Accept": "application/xml"}
for var, val in locals().items(): for var, val in locals().items():
if str(var) == "stopType": if str(var) == "stopType":
@@ -64,13 +65,8 @@ def stop_by_coords(accessId: str,
if val != None: if val != None:
payload[str(var)] = val payload[str(var)] = val
output = get("https://www.rmv.de/hapi/location.nearbystops", params=payload, headers=headers) output = get(
"https://www.rmv.de/hapi/location.nearbystops", params=payload, headers=headers
)
# Exceptions checker moved to normal methods return output.json() if json else xmlparse(output.content)
# and exceptions will no longer raise in raw ones.
# find_exception(output.json())
if json:
return output.json()
else:
return xmlparse(output.content)

View File

@@ -1,5 +1,6 @@
from requests import get
from typing import Union from typing import Union
from requests import get
from xmltodict import parse as xmlparse from xmltodict import parse as xmlparse
try: try:
@@ -7,33 +8,37 @@ try:
except ImportError: except ImportError:
from typing_extensions import Literal from typing_extensions import Literal
# 2.3. Location Search by Name (location.name) # 2.3. Location Search by Name (location.name)
def stop_by_name(accessId: str, def stop_by_name(
inputString: str, accessId: str,
lang: Literal["de", "da", "en", "es", "fr", "hu", "it", "nl", "no", "pl", "sv", "tr"] = "en", inputString: str,
json: bool = True, lang: Literal[
maxNo: int = 10, "de", "da", "en", "es", "fr", "hu", "it", "nl", "no", "pl", "sv", "tr"
stopType: Literal["A", "ALL", "AP", "P", "S", "SA", "SP"] = "ALL", ] = "en",
locationSelectionMode: Literal["SLCT_N", "SLCT_A"] = None, # type: ignore json: bool = True,
products: int = None, # type: ignore maxNo: int = 10,
coordLat: Union[str, float] = None, # type: ignore stopType: Literal["A", "ALL", "AP", "P", "S", "SA", "SP"] = "ALL",
coordLong: Union[str, float] = None, # type: ignore locationSelectionMode: Union[Literal["SLCT_N", "SLCT_A"], None] = None,
radius: Union[int, float] = 1000, products: Union[int, None] = None,
refineId: str = None, # type: ignore coordLat: Union[str, float, None] = None,
meta: str = None, # type: ignore coordLong: Union[str, float, None] = None,
stations: Union[str, list] = None, # type: ignore radius: Union[int, float] = 1000,
sattributes: Union[str, list] = None, # type: ignore refineId: Union[str, None] = None,
filterMode: Literal["DIST_PERI", "EXCL_PERI", "SLCT_PERI"] = "DIST_PERI" meta: Union[str, None] = None,
) -> dict: stations: Union[str, list, None] = None,
sattributes: Union[str, list, None] = None,
filterMode: Literal["DIST_PERI", "EXCL_PERI", "SLCT_PERI"] = "DIST_PERI",
) -> dict:
"""The location.name service can be used to perform a pattern matching of a user input and to retrieve a list """The location.name service can be used to perform a pattern matching of a user input and to retrieve a list
of possible matches in the journey planner database. Possible matches might be stops/stations, points of of possible matches in the journey planner database. Possible matches might be stops/stations, points of
interest and addresses. interest and addresses.
The result is a list of possible matches (locations) where the user might pick one entry to perform a trip The result is a list of possible matches (locations) where the user might pick one entry to perform a trip
request with this location as origin or destination or to ask for a departure board or arrival board of this request with this location as origin or destination or to ask for a departure board or arrival board of this
location (stops/stations only). location (stops/stations only).
Read more about this in section 2.3. "Location Search by Name (location.name)" of HAFAS ReST Documentation. Read more about this in section 2.3. "Location Search by Name (location.name)" of HAFAS ReST Documentation.
### Args: ### Args:
* accessId (str): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html). * accessId (str): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html).
@@ -55,14 +60,10 @@ def stop_by_name(accessId: str,
### Returns: ### Returns:
* dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs. * dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs.
""" """
if json:
headers = {"Accept": "application/json"}
else:
headers = {"Accept": "application/xml"}
payload = {} payload = {}
headers = {"Accept": "application/json"} if json else {"Accept": "application/xml"}
for var, val in locals().items(): for var, val in locals().items():
if str(var) == "inputString": if str(var) == "inputString":
@@ -80,11 +81,4 @@ def stop_by_name(accessId: str,
output = get("https://www.rmv.de/hapi/location.name", params=payload, headers=headers) output = get("https://www.rmv.de/hapi/location.name", params=payload, headers=headers)
# Exceptions checker moved to normal methods return output.json() if json else xmlparse(output.content)
# and exceptions will no longer raise in raw ones.
# find_exception(output.json())
if json:
return output.json()
else:
return xmlparse(output.content)

View File

@@ -1,6 +1,7 @@
from datetime import datetime from datetime import datetime
from requests import get
from typing import List, Union from typing import List, Union
from requests import get
from xmltodict import parse as xmlparse from xmltodict import parse as xmlparse
try: try:
@@ -8,125 +9,103 @@ try:
except ImportError: except ImportError:
from typing_extensions import Literal from typing_extensions import Literal
# 2.12. Trip Search (trip)
def trip_find(accessId: str,
lang: Literal["de", "da", "en", "es", "fr", "hu", "it", "nl", "no", "pl", "sv", "tr"] = "en",
json: bool = True,
originId: str = None, # type: ignore def trip_find(
originExtId: str = None, # type: ignore accessId: str,
originCoordLat: Union[str, float] = None, # type: ignore lang: Literal[
originCoordLong: Union[str, float] = None, # type: ignore "de", "da", "en", "es", "fr", "hu", "it", "nl", "no", "pl", "sv", "tr"
originCoordName: str = None, # type: ignore ] = "en",
json: bool = True,
destId: str = None, # type: ignore originId: Union[str, None] = None,
destExtId: str = None, # type: ignore originExtId: Union[str, None] = None,
destCoordLat: Union[str, float] = None, # type: ignore originCoordLat: Union[str, float, None] = None,
destCoordLong: Union[str, float] = None, # type: ignore originCoordLong: Union[str, float, None] = None,
destCoordName: str = None, # type: ignore originCoordName: Union[str, None] = None,
destId: Union[str, None] = None,
via: str = None, # type: ignore destExtId: Union[str, None] = None,
viaId: str = None, # type: ignore destCoordLat: Union[str, float, None] = None,
viaWaitTime: int = 0, destCoordLong: Union[str, float, None] = None,
destCoordName: Union[str, None] = None,
avoid: str = None, # type: ignore via: Union[str, None] = None,
avoidId: str = None, # type: ignore viaId: Union[str, None] = None,
viaWaitTime: int = 0,
viaGis: str = None, # type: ignore avoid: Union[str, None] = None,
avoidId: Union[str, None] = None,
changeTimePercent: int = 100, viaGis: Union[str, None] = None,
minChangeTime: int = None, # type: ignore changeTimePercent: int = 100,
maxChangeTime: int = None, # type: ignore minChangeTime: Union[int, None] = None,
addChangeTime: int = None, # type: ignore maxChangeTime: Union[int, None] = None,
maxChange: int = None, # type: ignore addChangeTime: Union[int, None] = None,
maxChange: Union[int, None] = None,
date: Union[str, datetime] = None, # type: ignore date: Union[str, datetime, None] = None,
time: Union[str, datetime] = None, # type: ignore time: Union[str, datetime, None] = None,
searchForArrival: bool = False,
searchForArrival: bool = False, numF: Union[int, None] = None,
numB: Union[int, None] = None,
numF: int = None, # type: ignore context: Union[str, None] = None,
numB: int = None, # type: ignore poly: bool = False,
polyEnc: Literal["DLT", "GPA", "N"] = "N",
context: str = None, # type: ignore passlist: bool = False,
products: Union[int, None] = None,
poly: bool = False, operators: Union[str, list, None] = None,
polyEnc: Literal["DLT", "GPA", "N"] = "N", attributes: Union[str, list, None] = None,
sattributes: Union[str, list, None] = None,
passlist: bool = False, fattributes: Union[str, list, None] = None,
products: int = None, # type: ignore lines: Union[str, list, None] = None,
operators: Union[str, list] = None, # type: ignore lineids: Union[str, list, None] = None,
avoidPaths: Union[List[Literal["SW", "EA", "ES", "RA", "CB"]], None] = None,
attributes: Union[str, list] = None, # type: ignore originWalk: Union[str, list, None] = None,
sattributes: Union[str, list] = None, # type: ignore originBike: Union[str, list, None] = None,
fattributes: Union[str, list] = None, # type: ignore originCar: Union[str, list, None] = None,
lines: Union[str, list] = None, # type: ignore originTaxi: Union[str, list, None] = None,
lineids: Union[str, list] = None, # type: ignore originPark: Union[str, list, None] = None,
originMeta: Union[str, list, None] = None,
avoidPaths: List[Literal["SW", "EA", "ES", "RA", "CB"]] = None, # type: ignore destWalk: Union[str, list, None] = None,
destBike: Union[str, list, None] = None,
originWalk: Union[str, list] = None, # type: ignore destCar: Union[str, list, None] = None,
originBike: Union[str, list] = None, # type: ignore destTaxi: Union[str, list, None] = None,
originCar: Union[str, list] = None, # type: ignore destPark: Union[str, list, None] = None,
originTaxi: Union[str, list] = None, # type: ignore destMeta: Union[str, list, None] = None,
originPark: Union[str, list] = None, # type: ignore totalWalk: Union[str, list, None] = None,
originMeta: Union[str, list] = None, # type: ignore totalBike: Union[str, list, None] = None,
totalCar: Union[str, list, None] = None,
destWalk: Union[str, list] = None, # type: ignore totalTaxi: Union[str, list, None] = None,
destBike: Union[str, list] = None, # type: ignore totalMeta: Union[str, list, None] = None,
destCar: Union[str, list] = None, # type: ignore gisProducts: Union[str, None] = None,
destTaxi: Union[str, list] = None, # type: ignore includeIv: bool = False,
destPark: Union[str, list] = None, # type: ignore ivOnly: bool = False,
destMeta: Union[str, list] = None, # type: ignore mobilityProfile: Union[str, None] = None,
bikeCarriage: bool = False,
totalWalk: Union[str, list] = None, # type: ignore bikeCarriageType: Union[
totalBike: Union[str, list] = None, # type: ignore Literal["SINGLEBIKES", "SMALLGROUPS", "LARGEGROUPS"], None
totalCar: Union[str, list] = None, # type: ignore ] = None,
totalTaxi: Union[str, list] = None, # type: ignore sleepingCar: bool = False,
totalMeta: Union[str, list] = None, # type: ignore couchetteCoach: bool = False,
showPassingPoints: bool = False,
gisProducts: str = None, # type: ignore baim: bool = False,
eco: bool = False,
includeIv: bool = False, ecoCmp: bool = False,
ivOnly: bool = False, ecoParams: Union[str, None] = None,
rtMode: Union[Literal["FULL", "INFOS", "OFF", "REALTIME", "SERVER_DEFAULT"], None] = None,
mobilityProfile: str = None, # type: ignore unsharp: bool = False,
trainFilter: Union[str, None] = None,
bikeCarriage: bool = False, economic: bool = False,
bikeCarriageType: Literal["SINGLEBIKES", "SMALLGROUPS", "LARGEGROUPS"] = None, # type: ignore groupFilter: Union[str, None] = None,
blockingList: Union[str, None] = None,
sleepingCar: bool = False, blockedEdges: Union[str, None] = None,
couchetteCoach: bool = False, trainComposition: bool = False,
showPassingPoints: bool = False, includeEarlier: bool = False,
baim: bool = False, withICTAlternatives: bool = False,
tariff: Union[bool, None] = None,
eco: bool = False, trafficMessages: bool = False,
ecoCmp: bool = False, travellerProfileData: Union[str, None] = None,
ecoParams: str = None, # type: ignore withFreq: bool = True,
) -> dict:
rtMode: Literal["FULL", "INFOS", "OFF", "REALTIME", "SERVER_DEFAULT"] = None, # type: ignore
unsharp: bool = False,
trainFilter: str = None, # type: ignore
economic: bool = False,
groupFilter: str = None, # type: ignore
blockingList: str = None, # type: ignore
blockedEdges: str = None, # type: ignore
trainComposition: bool = False,
includeEarlier: bool = False,
withICTAlternatives: bool = False,
tariff: bool = None, # type: ignore
trafficMessages: bool = False,
travellerProfileData: str = None, # type: ignore
withFreq: bool = True
) -> dict:
"""The trip service calculates a trip from a specified origin to a specified destination. These might be """The trip service calculates a trip from a specified origin to a specified destination. These might be
stop/station IDs or coordinates based on addresses and points of interest validated by the location service or stop/station IDs or coordinates based on addresses and points of interest validated by the location service or
coordinates freely defined by the client. coordinates freely defined by the client.
Read more about this in section 2.12. "Trip Search (trip)" of HAFAS ReST Documentation. Read more about this in section 2.12. "Trip Search (trip)" of HAFAS ReST Documentation.
### Args: ### Args:
* accessId (str): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html). * accessId (str): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html).
@@ -217,14 +196,10 @@ def trip_find(accessId: str,
### Returns: ### Returns:
* dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs. * dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs.
""" """
if json:
headers = {"Accept": "application/json"}
else:
headers = {"Accept": "application/xml"}
payload = {} payload = {}
headers = {"Accept": "application/json"} if json else {"Accept": "application/xml"}
for var, val in locals().items(): for var, val in locals().items():
if str(var) == "date": if str(var) == "date":
@@ -235,10 +210,9 @@ def trip_find(accessId: str,
payload[str(var)] = val payload[str(var)] = val
elif str(var) == "time": elif str(var) == "time":
if val != None: if val != None:
if isinstance(val, datetime): payload[str(var)] = (
payload[str(var)] = val.strftime("%H:%M") val.strftime("%H:%M") if isinstance(val, datetime) else val
else: )
payload[str(var)] = val
elif str(var) == "rtMode": elif str(var) == "rtMode":
if val != None: if val != None:
payload["rtMode"] = val.upper() payload["rtMode"] = val.upper()
@@ -248,11 +222,4 @@ def trip_find(accessId: str,
output = get("https://www.rmv.de/hapi/trip", params=payload, headers=headers) output = get("https://www.rmv.de/hapi/trip", params=payload, headers=headers)
# Exceptions checker moved to normal methods return output.json() if json else xmlparse(output.content)
# and exceptions will no longer raise in raw ones.
# find_exception(output.json())
if json:
return output.json()
else:
return xmlparse(output.content)

View File

@@ -1,6 +1,7 @@
from datetime import datetime from datetime import datetime
from requests import get
from typing import Union from typing import Union
from requests import get
from xmltodict import parse as xmlparse from xmltodict import parse as xmlparse
try: try:
@@ -8,43 +9,44 @@ try:
except ImportError: except ImportError:
from typing_extensions import Literal from typing_extensions import Literal
# 2.17. Reconstruction (recon)
def trip_recon(accessId: str, def trip_recon(
ctx: str, accessId: str,
json: bool = True, ctx: str,
poly: bool = False, json: bool = True,
polyEnc: Literal["DLT", "GPA", "N"] = "N", poly: bool = False,
date: Union[str, datetime] = None, # type: ignore polyEnc: Literal["DLT", "GPA", "N"] = "N",
useCombinedComparison: bool = None, # type: ignore date: Union[str, datetime, None] = None,
acceptGaps: bool = None, # type: ignore useCombinedComparison: Union[bool, None] = None,
allowDummySections: bool = None, # type: ignore acceptGaps: Union[bool, None] = None,
flagAllNonReachable: bool = None, # type: ignore allowDummySections: Union[bool, None] = None,
matchCatStrict: bool = None, # type: ignore flagAllNonReachable: Union[bool, None] = None,
matchIdNonBlank: bool = None, # type: ignore matchCatStrict: Union[bool, None] = None,
matchIdStrict: bool = None, # type: ignore matchIdNonBlank: Union[bool, None] = None,
matchNumStrict: bool = None, # type: ignore matchIdStrict: Union[bool, None] = None,
matchRtType: bool = None, # type: ignore matchNumStrict: Union[bool, None] = None,
enableRtFullSearch: bool = None, # type: ignore matchRtType: Union[bool, None] = None,
enableReplacements: bool = None, # type: ignore enableRtFullSearch: Union[bool, None] = None,
arrL: int = None, # type: ignore enableReplacements: Union[bool, None] = None,
arrU: int = None, # type: ignore arrL: Union[int, None] = None,
depL: int = None, # type: ignore arrU: Union[int, None] = None,
depU: int = None, # type: ignore depL: Union[int, None] = None,
passlist: bool = False, depU: Union[int, None] = None,
showPassingPoints: bool = False, passlist: bool = False,
rtMode: Literal["FULL", "INFOS", "OFF", "REALTIME", "SERVER_DEFAULT"] = None, # type: ignore showPassingPoints: bool = False,
eco: bool = False, rtMode: Union[Literal["FULL", "INFOS", "OFF", "REALTIME", "SERVER_DEFAULT"], None] = None,
ecoCmp: bool = False, eco: bool = False,
ecoParams: str = None, # type: ignore ecoCmp: bool = False,
tariff: bool = None, # type: ignore ecoParams: Union[str, None] = None,
trafficMessages: bool = None, # type: ignore tariff: Union[bool, None] = None,
travellerProfileData: str = None # type: ignore trafficMessages: Union[bool, None] = None,
) -> dict: travellerProfileData: Union[str, None] = None,
) -> dict:
"""Reconstructing a trip can be achieved using the reconstruction context provided by any trip result in the """Reconstructing a trip can be achieved using the reconstruction context provided by any trip result in the
ctxRecon attribute of Trip element. The result will be a true copy of the original trip search result given ctxRecon attribute of Trip element. The result will be a true copy of the original trip search result given
that the underlying data did not change. that the underlying data did not change.
Read more about this in section 2.17. "Reconstruction (recon)" of HAFAS ReST Documentation. Read more about this in section 2.17. "Reconstruction (recon)" of HAFAS ReST Documentation.
### Args: ### Args:
* accessId (str): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html). * accessId (str): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html).
@@ -80,14 +82,10 @@ def trip_recon(accessId: str,
### Returns: ### Returns:
* dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs. * dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs.
""" """
if json:
headers = {"Accept": "application/json"}
else:
headers = {"Accept": "application/xml"}
payload = {} payload = {}
headers = {"Accept": "application/json"} if json else {"Accept": "application/xml"}
for var, val in locals().items(): for var, val in locals().items():
if str(var) == "date": if str(var) == "date":
@@ -102,11 +100,4 @@ def trip_recon(accessId: str,
output = get("https://www.rmv.de/hapi/recon", params=payload, headers=headers) output = get("https://www.rmv.de/hapi/recon", params=payload, headers=headers)
# Exceptions checker moved to normal methods return output.json() if json else xmlparse(output.content)
# and exceptions will no longer raise in raw ones.
# find_exception(output.json())
if json:
return output.json()
else:
return xmlparse(output.content)

View File

@@ -0,0 +1,3 @@
from .find_exception import find_exception
from .journey_ref_converter import ref_upgrade
from .weekdays_bitmask import weekdays_bitmask

View File

@@ -1,22 +1,46 @@
from pyrmv.errors.api_errors import ApiAuthError, ApiFormatError, ApiParamError, ApiQuotaError, ApiTooManyRequests from pyrmv.errors import (
from pyrmv.errors.int_errors import IntError, IntGatewayError, IntTimeoutError ApiAuthError,
from pyrmv.errors.ps_errors import PsIncorrectParamError ApiFormatError,
from pyrmv.errors.sot_errors import SotAllTrainsFilteredError, SotAlreadyArrivedError, SotCancelledError, SotNotStartedError, SotStayOnTripError ApiParamError,
from pyrmv.errors.svc_errors import SvcContextError, SvcDatetimeError, SvcDatetimePeriodError, SvcLocationArrivalError, SvcLocationDepartureError, SvcLocationEqualError, SvcLocationError, SvcLocationNearError, SvcLocationViaError, SvcNoMatchError, SvcNoResultError, SvcProductError, SvcSearchError ApiQuotaError,
from pyrmv.errors.unknown_error import UnknownError ApiTooManyRequests,
IntError,
IntGatewayError,
IntTimeoutError,
PsIncorrectParamError,
SotAllTrainsFilteredError,
SotAlreadyArrivedError,
SotCancelledError,
SotNotStartedError,
SotStayOnTripError,
SvcContextError,
SvcDatetimeError,
SvcDatetimePeriodError,
SvcLocationArrivalError,
SvcLocationDepartureError,
SvcLocationEqualError,
SvcLocationError,
SvcLocationNearError,
SvcLocationViaError,
SvcNoMatchError,
SvcNoResultError,
SvcProductError,
SvcSearchError,
UnknownError,
)
def find_exception(data: dict): def find_exception(data: dict):
"""Scan returned dict for errorCode from RMV. """Scan returned dict for errorCode from RMV.
Raises different exceptions if errorCode is not None. Raises different exceptions if errorCode is not None.
### Args: ### Args:
* data (dict): Response from RMV as a dict. * data (dict): Response from RMV as a dict.
### Raises: ### Raises:
* Any: Formatted as "errorCode -> errorText" if ApiParamError and UnknownError or as a single massage for others. * Any: Formatted as "errorCode -> errorText" if ApiParamError and UnknownError or as a single massage for others.
""" """
if "errorCode" in data: if "errorCode" in data:
if data["errorCode"] == "API_AUTH": if data["errorCode"] == "API_AUTH":
raise ApiAuthError() raise ApiAuthError()
@@ -25,7 +49,7 @@ def find_exception(data: dict):
elif data["errorCode"] == "API_TOO_MANY_REQUESTS": elif data["errorCode"] == "API_TOO_MANY_REQUESTS":
raise ApiTooManyRequests() raise ApiTooManyRequests()
elif data["errorCode"] == "API_PARAM": elif data["errorCode"] == "API_PARAM":
raise ApiParamError(errorCode=data["errorCode"], errorText=data["errorText"]) raise ApiParamError(errorCode=data["errorCode"], errorText=data["errorText"])
@@ -99,4 +123,4 @@ def find_exception(data: dict):
raise PsIncorrectParamError() raise PsIncorrectParamError()
else: else:
raise UnknownError(errorCode=data["errorCode"], errorText=data["errorText"]) raise UnknownError(errorCode=data["errorCode"], errorText=data["errorText"])

View File

@@ -0,0 +1,26 @@
def ref_upgrade(ref: str) -> str:
"""This function converts older journey refs to the newer ones.
### WARNING
This function will be deprecated as soon as RMV updates their API
### Args:
* ref (`str`): Old ref like this one: `2|#VN#1#ST#1700765441#PI#0#ZI#160749#TA#0#DA#241123#1S#3004646#1T#2228#LS#3006907#LT#2354#PU#80#RT#1#CA#S30#ZE#S1#ZB# S1#PC#3#FR#3004646#FT#2228#TO#3006907#TT#2354#`
### Raises:
* `KeyError`: Some required keys are not found in the ref provided
### Returns:
* `str`: Ref of the new type
"""
items = "|".join(ref.split("|")[1:]).strip("#").split("#")
result = {items[i]: items[i + 1] for i in range(0, len(items), 2)}
for required in ["VN", "ZI", "TA", "PU"]:
if required not in result:
raise KeyError(
f"Required key {required} in the old journey ref is not found during conversion to the newer journey ref"
)
return "|".join([result["VN"], result["ZI"], result["TA"], result["PU"]])

View File

@@ -9,13 +9,10 @@ def weekdays_bitmask(data: OrderedDict[str, bool]) -> str:
### Returns: ### Returns:
* str: _description_ * str: _description_
""" """
output = ""
if len(data) != 7: if len(data) != 7:
raise ValueError("OrderedDict must be formatted as follows: OrderedDict(Monday=bool, Tuesday=bool, Wednesday=bool, Thursday=bool, Friday=bool, Saturday=bool, Sunday=bool)") raise ValueError(
for day in data: "OrderedDict must be formatted as follows: OrderedDict(Monday=bool, Tuesday=bool, Wednesday=bool, Thursday=bool, Friday=bool, Saturday=bool, Sunday=bool)"
if data[day]: )
output += "1"
else: return "".join("1" if data[day] else "0" for day in data)
output += "0"
return output

82
test.py
View File

@@ -1,82 +0,0 @@
from datetime import datetime, timedelta
from os import makedirs
from typing import Union
from ujson import loads, dumps, JSONDecodeError
from test_colors import *
import pyrmv
try:
with open("test_key.json", mode="r", encoding="utf-8") as file:
key = loads(file.read())["key"]
file.close()
except FileNotFoundError:
key = input("File 'test_key.json' does not exist. Enter your RMV API key to continue: ").strip()
key_save = input("To skip entering your key every time I can save your apikey here. Should I do that? (Y/n) > ").strip().lower()
if key_save == "y":
try:
with open("test_key.json", mode="w", encoding="utf-8") as file:
file.write(dumps({"key": key}))
file.close()
except Exception as exp:
print(f"Could not save 'test_key.json' with your apikey due to {exp}", flush=True)
else:
print("To skip entering your key every time create file 'test_key.json' with your apikey as a value for 'key' dict key.", flush=True)
def test(name: str, data: Union[str, dict], raw: bool = False) -> None:
makedirs("tests", exist_ok=True)
if isinstance(data, dict):
if "errorCode" in data:
print(f"{BBLACK}[{BRED}ER{BBLACK}] {RESET}Test of {YELLOW}{name} {RESET}did not go well. ErrorCode is {BRED}{data['errorCode']}{RESET}. Check {CYAN}tests/{name}.json {RESET}for more information.", flush=True)
else:
print(f"{BBLACK}[{BGREEN}OK{BBLACK}] {RESET}Test of {YELLOW}{name} {RESET}seems to be alright.", flush=True)
if raw:
try:
with open(f"tests/{name}.json", "w", encoding="utf-8") as file:
file.write(dumps(data, indent=4, ensure_ascii=False))
file.close()
except JSONDecodeError:
print(f"{BBLACK}[{BRED}ER{BBLACK}] {RESET}Test of {YELLOW}{name} {RESET}did not go well. ErrorCode is {BRED}{data['errorCode']}{RESET}. Check {CYAN}tests/{name}.json {RESET}for more information.", flush=True)
else:
with open(f"tests/{name}.txt", "w", encoding="utf-8") as file:
if isinstance(data, list):
list_2 = []
for item in data:
list_2.append(str(item)+"\n")
file.writelines(list_2)
else:
file.write(str(data))
file.close()
if data in ["", "\n"]:
print(f"{BBLACK}[{BRED}ER{BBLACK}] {RESET}Test of {YELLOW}{name} {RESET}did not go well. ErrorCode is {BRED}{data['errorCode']}{RESET}. Check {CYAN}tests/{name}.txt {RESET}for more information.", flush=True)
else:
print(f"{BBLACK}[{BGREEN}OK{BBLACK}] {RESET}Test of {YELLOW}{name} {RESET}is not empty, so might be fine. Check {CYAN}tests/{name}.txt {RESET}for more information.", flush=True)
client = pyrmv.Client(key)
test("raw_board_arrival", pyrmv.raw.board_arrival(key, id="A=1@O=Offenbach (Main)-Tempelsee Wilhelm-Schramm-Straße@X=8783648@Y=50083822@U=80@L=3008012@", maxJourneys=5), raw=True)
test("raw_board_departure", pyrmv.raw.board_departure(key, id="A=1@O=Offenbach (Main)-Tempelsee Wilhelm-Schramm-Straße@X=8783648@Y=50083822@U=80@L=3008012@", maxJourneys=5), raw=True)
test("raw_him_search", pyrmv.raw.him_search(key, dateE=datetime.now()+timedelta(days=10), timeE=datetime.now()+timedelta(days=10), minprio=2, trainnames=["S9"]), raw=True)
test("raw_journey_detail", pyrmv.raw.journey_detail(key, id="2|#VN#1#ST#1664906549#PI#0#ZI#12709#TA#0#DA#61022#1S#3008007#1T#1248#LS#3008043#LT#1323#PU#80#RT#1#CA#1aE#ZE#101#ZB#Bus 101 #PC#6#FR#3008007#FT#1248#TO#3008043#TT#1323#"), raw=True)
test("raw_stop_by_name", pyrmv.raw.stop_by_name(key, "Groß Karben", maxNo=3), raw=True)
test("raw_stop_by_coords", pyrmv.raw.stop_by_coords(key, 50.131140, 8.733362, radius=300, maxNo=3), raw=True)
test("raw_trip_find", pyrmv.raw.trip_find(key, originCoordLat="50.084659", originCoordLong="8.785948", destCoordLat=50.1233048, destCoordLong=8.6129742, trafficMessages=True, numF=3), raw=True)
test("raw_trip_recon", pyrmv.raw.trip_recon(key, ctx="¶HKI¶G@F$A=2@O=50.084659, 8.785948@X=8785948@Y=50084659@u=0@a=128@$A=1@O=Offenbach (Main)-Tempelsee Wilhelm-Schramm-Straße@L=3008012@a=128@$202210061243$202210061247$$$1$$$$$$§T$A=1@O=Offenbach (Main)-Tempelsee Wilhelm-Schramm-Straße@L=3008012@a=128@$A=1@O=Offenbach (Main)-Zentrum Marktplatz\/Frankf. Straße@L=3002510@a=128@$202210061247$202210061300$Bus 101 $$1$$$$$$§W$A=1@O=Offenbach (Main)-Zentrum Marktplatz\/Frankf. Straße@L=3002510@a=128@$A=1@O=Offenbach (Main)-Zentrum Marktplatz@L=3011265@a=128@$202210061300$202210061304$$$1$$$$$$§T$A=1@O=Offenbach (Main)-Zentrum Marktplatz@L=3011265@a=128@$A=1@O=Frankfurt (Main) Taunusanlage@L=3000011@a=128@$202210061306$202210061319$ S2$$1$$$$$$§T$A=1@O=Frankfurt (Main) Taunusanlage@L=3000011@a=128@$A=1@O=Frankfurt (Main) Rödelheim Bahnhof@L=3001217@a=128@$202210061322$202210061333$ S5$$1$$$$$$§G@F$A=1@O=Frankfurt (Main) Rödelheim Bahnhof@L=3001217@a=128@$A=2@O=50.123304, 8.612974@X=8612974@Y=50123304@u=0@a=128@$202210061333$202210061344$$$1$$$$$$¶GP¶ft@0@2000@120@1@100@1@@0@@@@@false@0@-1@0@-1@-1@$f@$f@$f@$f@$f@$§bt@0@2000@120@1@100@1@@0@@@@@false@0@-1@0@-1@-1@$f@$f@$f@$f@$f@$§tt@0@2000@120@1@100@1@@0@@@@@false@0@-1@0@-1@-1@$f@$f@$f@$f@$f@$§¶KRCC¶#VE#1#"), raw=True)
test("board_arrival", client.board_arrival("A=1@O=Frankfurt (Main) Taunusanlage@X=8668765@Y=50113478@U=80@L=3000011@", journeys_max=5))
test("board_departure", client.board_departure("A=1@O=Frankfurt (Main) Taunusanlage@X=8668765@Y=50113478@U=80@L=3000011@", journeys_max=5))
test("him_search", client.him_search(date_end=datetime.now()+timedelta(days=10), priority_min=2, train_names=["S9"]))
test("journey_detail", client.journey_detail("2|#VN#1#ST#1664906549#PI#0#ZI#12709#TA#0#DA#61022#1S#3008007#1T#1248#LS#3008043#LT#1323#PU#80#RT#1#CA#1aE#ZE#101#ZB#Bus 101 #PC#6#FR#3008007#FT#1248#TO#3008043#TT#1323#", real_time_mode=pyrmv.enums.RealTimeMode.FULL))
test("stop_by_coords", client.stop_by_coords(50.131140, 8.733362, radius=300, max_number=3))
test("stop_by_id", client.stop_by_id("A=1@O=Offenbach (Main)-Zentrum Marktplatz\/Frankf. Straße@X=8764456@Y=50105181@U=80@L=3002510@"))
test("stop_by_name", client.stop_by_name("Groß Karben", max_number=3))
test("trip_find", client.trip_find(origin_coord_lat="50.084659", origin_coord_lon="8.785948", destination_coord_lat=50.1233048, destination_coord_lon=8.6129742, messages=True))
test("trip_recon", client.trip_recon( client.trip_find(origin_coord_lat="50.084659", origin_coord_lon="8.785948", destination_coord_lat=50.1233048, destination_coord_lon=8.6129742, messages=True, trips_after_time=1)[0] ))

View File

@@ -1,19 +0,0 @@
RESET = '\u001b[0m'
BLACK = '\u001b[30m'
RED = '\u001b[31m'
GREEN = '\u001b[32m'
YELLOW = '\u001b[33m'
BLUE = '\u001b[34m'
MAGENTA = '\u001b[35m'
CYAN = '\u001b[36m'
WHITE = '\u001b[37m'
BBLACK = '\u001b[30;1m'
BRED = '\u001b[31;1m'
BGREEN = '\u001b[32;1m'
BYELLOW = '\u001b[33;1m'
BBLUE = '\u001b[34;1m'
BMAGENTA = '\u001b[35;1m'
BCYAN = '\u001b[36;1m'
BWHITE = '\u001b[37;1m'
ULINE = '\u001b[4m'
REVERSE = '\u001b[7m'

36
tests/conftest.py Normal file
View File

@@ -0,0 +1,36 @@
from os import environ
from typing import List
import pytest
from pyrmv import Client
@pytest.fixture()
def api_token() -> str:
return environ.get("RMV_TOKEN")
@pytest.fixture()
def api_client(api_token: str) -> Client:
return Client(api_token)
@pytest.fixture()
def sample_stop_id() -> str:
return "A=1@O=Frankfurt (Main) Taunusanlage@X=8668765@Y=50113478@U=80@L=3000011@"
@pytest.fixture()
def sample_journey_id() -> str:
return "1|12709|0|80"
@pytest.fixture()
def sample_origin() -> List[str]:
return ["50.084659", "8.785948"]
@pytest.fixture()
def sample_destination() -> List[float]:
return [50.1233048, 8.6129742]

82
tests/test_client.py Normal file
View File

@@ -0,0 +1,82 @@
from datetime import datetime, timedelta
from typing import List
import pytest
from pyrmv import Client, enums
from pyrmv.classes import Journey, Message, Stop, Trip
from pyrmv.classes.board import BoardArrival, BoardDeparture
def test_board_arrival(api_client: Client, sample_stop_id: str):
assert isinstance(
api_client.board_arrival(id=sample_stop_id, journeys_max=3), BoardArrival
)
def test_board_departure(api_client: Client, sample_stop_id: str):
assert isinstance(
api_client.board_departure(id=sample_stop_id, journeys_max=3), BoardDeparture
)
def test_him_search(api_client: Client):
assert isinstance(
api_client.him_search(date_end=datetime.now() + timedelta(days=10))[0], Message
)
def test_journey_detail(api_client: Client, sample_journey_id: str):
assert (
api_client.journey_detail(
sample_journey_id,
real_time_mode=enums.RealTimeMode.FULL,
),
Journey,
)
def test_stop_by_coords(api_client: Client, sample_origin: List[str]):
assert isinstance(
api_client.stop_by_coords(sample_origin[0], sample_origin[1], max_number=3)[0], Stop
)
def test_stop_by_id(api_client: Client, sample_stop_id: str):
assert isinstance(api_client.stop_by_id(sample_stop_id), Stop)
def test_trip_find(
api_client: Client, sample_origin: List[str], sample_destination: List[float]
):
assert isinstance(
api_client.trip_find(
origin_coord_lat=sample_origin[0],
origin_coord_lon=sample_origin[1],
destination_coord_lat=sample_destination[0],
destination_coord_lon=sample_destination[1],
messages=True,
)[0],
Trip,
)
def test_trip_recon(
api_client: Client, sample_origin: List[str], sample_destination: List[float]
):
assert isinstance(
api_client.trip_recon(
api_client.trip_find(
origin_coord_lat=sample_origin[0],
origin_coord_lon=sample_origin[1],
destination_coord_lat=sample_destination[0],
destination_coord_lon=sample_destination[1],
messages=True,
)[0],
)[0],
Trip,
)
def test_stop_by_name(api_client: Client):
assert isinstance(api_client.stop_by_name("Hauptwache", max_number=1)[0], Stop)

7
tests/test_raw.py Normal file
View File

@@ -0,0 +1,7 @@
import pytest
from pyrmv.raw import stop_by_name
def test_stop_by_name(api_token: str):
assert isinstance(stop_by_name(api_token, "Hauptwache", maxNo=1), dict)

23
tox.ini Normal file
View File

@@ -0,0 +1,23 @@
[tox]
minversion = 3.8.0
envlist = py38, py39, py310, py311
isolated_build = true
[gh-actions]
python =
3.8: py38
3.9: py39
3.10: py310
3.11: py311
[testenv]
setenv =
PYTHONPATH = {toxinidir}
passenv =
RMV_TOKEN
deps =
-r{toxinidir}/requirements/_.txt
-r{toxinidir}/requirements/dev.txt
commands =
pytest --basetemp={envtmpdir} --cov=pyrmv --cov-report term-missing

39
wiki/Home.md Normal file
View File

@@ -0,0 +1,39 @@
# PythonRMV
Welcome to the project's Wiki.
This module aims to provide eased access to RMV's OpenData API endpoints and enable some home-projects to show the data about public transit state at the moment. As for now, async is not supported and is not necessarily planned in the future, so bigger projects should consider this before using this module in the first place.
## Basic concepts behind
So the module `pyrmv` has two options to choose from when it comes to the usage:
1. Using higher-level methods of the class [pyrmv.Client](https://git.end-play.xyz/profitroll/PythonRMV/wiki/Client). These methods provide pythonic objects, can throw exceptions and are overall pretty neat.
2. Using raw functions from [pyrmv.raw](https://git.end-play.xyz/profitroll/PythonRMV/wiki/Raw-Functions). These functions are basically a small interface for HTTP requests that happen in the background and have little to no processing behind the scenes.
Your preferred variant depends on the use case, but usually higher-level methods of the Client should be the match.
## Objects
This module does **not** use the [FPTF](https://github.com/public-transport/friendly-public-transport-format) because it aims to give full access to the API RMV provides, thus objects Client gives you will contain a bit more information.
These objects are implemented in pyrmv:
* [BoardArrival](https://git.end-play.xyz/profitroll/PythonRMV/wiki/classes.BoardArrival)
* [BoardDeparture](https://git.end-play.xyz/profitroll/PythonRMV/wiki/classes.BoardDeparture)
* [LineArrival](https://git.end-play.xyz/profitroll/PythonRMV/wiki/classes.LineArrival)
* [LineDeparture](https://git.end-play.xyz/profitroll/PythonRMV/wiki/classes.LineDeparture)
* [Gis](https://git.end-play.xyz/profitroll/PythonRMV/wiki/classes.Gis)
* [Journey](https://git.end-play.xyz/profitroll/PythonRMV/wiki/classes.Journey)
* [Leg](https://git.end-play.xyz/profitroll/PythonRMV/wiki/classes.Leg)
* [Channel](https://git.end-play.xyz/profitroll/PythonRMV/wiki/classes.Channel)
* [Message](https://git.end-play.xyz/profitroll/PythonRMV/wiki/classes.Message)
* [Url](https://git.end-play.xyz/profitroll/PythonRMV/wiki/classes.Url)
* [Stop](https://git.end-play.xyz/profitroll/PythonRMV/wiki/classes.Stop)
* [StopTrip](https://git.end-play.xyz/profitroll/PythonRMV/wiki/classes.StopTrip)
* [Trip](https://git.end-play.xyz/profitroll/PythonRMV/wiki/classes.Trip)
* ~~[Ticket](https://git.end-play.xyz/profitroll/PythonRMV/wiki/classes.Ticket)~~ (WIP)
## Note for bigger projects
As you may already know, bigger projects like [Öffi](https://gitlab.com/oeffi/oeffi) and [DB Navigator](https://play.google.com/store/apps/details?id=de.hafas.android.db) use NVV's API instead of RMV's for navigation and public transit querying. Reasons behind this are clear as day and from perspective of pyrmv it's highly recommended you also choose that way, because RMV loves to change or break their API in unexpected places and does not cooperate with developers well enough when they do so.

1
wiki/Raw-Functions.md Normal file
View File

@@ -0,0 +1 @@
Docs are not available yet. Please, use the linting in your IDE until the documentation is there.

21
wiki/_Sidebar.md Normal file
View File

@@ -0,0 +1,21 @@
# [Home](https://git.end-play.xyz/profitroll/PythonRMV/wiki)
## Classes
* [Client](https://git.end-play.xyz/profitroll/PythonRMV/wiki/classes.Client)
## Methods
* [board_arrival](https://git.end-play.xyz/profitroll/PythonRMV/wiki/classes.Client.board_arrival)
* [board_departure](https://git.end-play.xyz/profitroll/PythonRMV/wiki/classes.Client.board_departure)
* [him_search](https://git.end-play.xyz/profitroll/PythonRMV/wiki/classes.Client.him_search)
* [journey_detail](https://git.end-play.xyz/profitroll/PythonRMV/wiki/classes.Client.journey_detail)
* [stop_by_coords](https://git.end-play.xyz/profitroll/PythonRMV/wiki/classes.Client.stop_by_coords)
* [stop_by_id](https://git.end-play.xyz/profitroll/PythonRMV/wiki/classes.Client.stop_by_id)
* [stop_by_name](https://git.end-play.xyz/profitroll/PythonRMV/wiki/classes.Client.stop_by_name)
* [trip_find](https://git.end-play.xyz/profitroll/PythonRMV/wiki/classes.Client.trip_find)
* [trip_recon](https://git.end-play.xyz/profitroll/PythonRMV/wiki/classes.Client.trip_recon)
## Raw functions
* [List of raw functions](https://git.end-play.xyz/profitroll/PythonRMV/wiki/Raw-Functions)

View File

@@ -0,0 +1 @@
Docs are not available yet. Please, use the linting in your IDE until the documentation is there.

View File

@@ -0,0 +1 @@
Docs are not available yet. Please, use the linting in your IDE until the documentation is there.

1
wiki/classes/Channel.md Normal file
View File

@@ -0,0 +1 @@
Docs are not available yet. Please, use the linting in your IDE until the documentation is there.

View File

@@ -0,0 +1,31 @@
# Client
You are now viewing the main class of the module, all available higher-level methods can be found here.
This page is about the Client class, which exposes high-level methods for an easy access to the API.
```py
from pyrmv import Client
client = Client("SampleAPIKey")
print(client.stop_by_id("A=1@O=Offenbach (Main)-Zentrum Marktplatz\/Frankf. Straße@X=8764456@Y=50105181@U=80@L=3002510@"))
```
## Details
### Parameters
* access_key (`str`) Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html).
### Methods
* [board_arrival](https://git.end-play.xyz/profitroll/PythonRMV/wiki/board_arrival) -> `BoardArrival`
* [board_departure](https://git.end-play.xyz/profitroll/PythonRMV/wiki/board_departure) -> `BoardDeparture`
* [him_search](https://git.end-play.xyz/profitroll/PythonRMV/wiki/him_search) -> `List[Message]`
* [journey_detail](https://git.end-play.xyz/profitroll/PythonRMV/wiki/journey_detail) -> `Journey`
* [stop_by_coords](https://git.end-play.xyz/profitroll/PythonRMV/wiki/stop_by_coords) -> `List[Stop]`
* [stop_by_id](https://git.end-play.xyz/profitroll/PythonRMV/wiki/stop_by_id) -> `Union[Stop, None]`
* [stop_by_name](https://git.end-play.xyz/profitroll/PythonRMV/wiki/stop_by_name) -> `List[Stop]`
* [trip_find](https://git.end-play.xyz/profitroll/PythonRMV/wiki/trip_find) -> `List[Trip]`
* [trip_recon](https://git.end-play.xyz/profitroll/PythonRMV/wiki/trip_recon) -> `List[Trip]`

View File

@@ -0,0 +1 @@
Docs are not available yet. Please, use the linting in your IDE until the documentation is there.

View File

@@ -0,0 +1 @@
Docs are not available yet. Please, use the linting in your IDE until the documentation is there.

View File

@@ -0,0 +1 @@
Docs are not available yet. Please, use the linting in your IDE until the documentation is there.

View File

@@ -0,0 +1 @@
Docs are not available yet. Please, use the linting in your IDE until the documentation is there.

View File

@@ -0,0 +1 @@
Docs are not available yet. Please, use the linting in your IDE until the documentation is there.

View File

@@ -0,0 +1 @@
Docs are not available yet. Please, use the linting in your IDE until the documentation is there.

View File

@@ -0,0 +1 @@
Docs are not available yet. Please, use the linting in your IDE until the documentation is there.

View File

@@ -0,0 +1 @@
Docs are not available yet. Please, use the linting in your IDE until the documentation is there.

View File

@@ -0,0 +1 @@
Docs are not available yet. Please, use the linting in your IDE until the documentation is there.

1
wiki/classes/Gis.md Normal file
View File

@@ -0,0 +1 @@
Docs are not available yet. Please, use the linting in your IDE until the documentation is there.

1
wiki/classes/Journey.md Normal file
View File

@@ -0,0 +1 @@
Docs are not available yet. Please, use the linting in your IDE until the documentation is there.

1
wiki/classes/Leg.md Normal file
View File

@@ -0,0 +1 @@
Docs are not available yet. Please, use the linting in your IDE until the documentation is there.

View File

@@ -0,0 +1 @@
Docs are not available yet. Please, use the linting in your IDE until the documentation is there.

View File

@@ -0,0 +1 @@
Docs are not available yet. Please, use the linting in your IDE until the documentation is there.

1
wiki/classes/Message.md Normal file
View File

@@ -0,0 +1 @@
Docs are not available yet. Please, use the linting in your IDE until the documentation is there.

1
wiki/classes/Stop.md Normal file
View File

@@ -0,0 +1 @@
Docs are not available yet. Please, use the linting in your IDE until the documentation is there.

1
wiki/classes/StopTrip.md Normal file
View File

@@ -0,0 +1 @@
Docs are not available yet. Please, use the linting in your IDE until the documentation is there.

1
wiki/classes/Ticket.md Normal file
View File

@@ -0,0 +1 @@
Class is not available yet. Documentation will appear here after the class is finished.

1
wiki/classes/Trip.md Normal file
View File

@@ -0,0 +1 @@
Docs are not available yet. Please, use the linting in your IDE until the documentation is there.

1
wiki/classes/Url.md Normal file
View File

@@ -0,0 +1 @@
Docs are not available yet. Please, use the linting in your IDE until the documentation is there.