7 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
37 changed files with 231 additions and 38 deletions

View File

@@ -19,13 +19,11 @@ If you have everything listed in [requirements](#requirements), then let's begin
### Variant 1
1. `python -m pip install pyrmv`
`python -m pip install pyrmv`
### Variant 2
1. `git clone https://git.end-play.xyz/profitroll/PythonRMV.git`
2. `cd PythonRMV`
3. `python setup.py install`
`python -m pip install git+https://git.end-play.xyz/profitroll/PythonRMV.git`
## Usage
@@ -39,7 +37,7 @@ client = pyrmv.Client("AcessId")
origin = client.stop_by_name("Frankfurt Hauptbahnhof", 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)
```

View File

@@ -21,7 +21,7 @@ trip = client.trip_find(origin_id=origin.id, dest_id=destination.id)
"""
__name__ = "pyrmv"
__version__ = "1.0.0"
__version__ = "0.4.0-rc.1"
__license__ = "MIT License"
__author__ = "Profitroll"

View File

@@ -1,5 +1,4 @@
from .board import BoardArrival, BoardDeparture, LineArrival, LineDeparture
from .client import Client
from .gis import Gis
from .journey import Journey
from .leg import Leg

View File

@@ -2,11 +2,15 @@ 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):
self.journey = client.journey_detail(data["JourneyDetailRef"]["ref"])
# 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"]
@@ -40,7 +44,10 @@ class LineArrival:
class LineDeparture:
def __init__(self, data: Mapping[str, Any], client, retrieve_stops: bool = True):
self.journey = client.journey_detail(data["JourneyDetailRef"]["ref"])
# 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"]

View File

@@ -121,7 +121,7 @@ class Client:
* BoardArrival: Instance of `BoardArrival` object.
"""
if isinstance(direction, Stop) or isinstance(direction, StopTrip):
if isinstance(direction, (Stop, StopTrip)):
direction = direction.id
board_raw = raw_board_arrival(
@@ -827,10 +827,7 @@ class Client:
* List[Trip]: List of `Trip` objects. Empty list if none found.
"""
if real_time_mode == None:
real_time_mode = None
else:
real_time_mode = real_time_mode.code
real_time_mode = None if real_time_mode is None else real_time_mode.code
if isinstance(context, Trip):
context = context.ctx_recon

View File

@@ -2,6 +2,7 @@ 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:
@@ -9,7 +10,11 @@ class Journey:
def __init__(self, data: Mapping[str, Any]):
self.stops = []
self.ref = data["ref"]
# 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"])

View File

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

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

@@ -1,4 +1,5 @@
from os import environ
from typing import List
import pytest
@@ -13,3 +14,23 @@ def api_token() -> str:
@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]

View File

@@ -1,7 +1,81 @@
from datetime import datetime, timedelta
from typing import List
import pytest
from pyrmv import Client
from pyrmv.classes import Stop
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):

View File

@@ -2,4 +2,38 @@
Welcome to the project's Wiki.
Conceptional there are two different types of methods. Normal and raw ones. Raw methods are only beautiful variant of HTTP requests, nothing except for that actually. Normal ones are meant to be used as objects. You can still provide strings here and there, but basic concept is focused on objects usage.
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.

View File

@@ -1,15 +1,21 @@
## [Home](https://git.end-play.xyz/profitroll/PythonRMV/wiki)
# [Home](https://git.end-play.xyz/profitroll/PythonRMV/wiki)
### Classes
* [Client](https://git.end-play.xyz/profitroll/PythonRMV/wiki/Client)
## Classes
### Methods
* [board_arrival](https://git.end-play.xyz/profitroll/PythonRMV/wiki/board_arrival)
* [board_departure](https://git.end-play.xyz/profitroll/PythonRMV/wiki/board_departure)
* [him_search](https://git.end-play.xyz/profitroll/PythonRMV/wiki/him_search)
* [journey_detail](https://git.end-play.xyz/profitroll/PythonRMV/wiki/journey_detail)
* [stop_by_coords](https://git.end-play.xyz/profitroll/PythonRMV/wiki/stop_by_coords)
* [stop_by_id](https://git.end-play.xyz/profitroll/PythonRMV/wiki/stop_by_id)
* [stop_by_name](https://git.end-play.xyz/profitroll/PythonRMV/wiki/stop_by_name)
* [trip_find](https://git.end-play.xyz/profitroll/PythonRMV/wiki/trip_find)
* [trip_recon](https://git.end-play.xyz/profitroll/PythonRMV/wiki/trip_recon)
* [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

@@ -1,5 +1,6 @@
# PythonRMV Client
You are now viewing the main class of the module, its heart. The main Client class, all available normal methods can be found here.
# 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.
@@ -11,14 +12,14 @@ 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
## `class pyrmv.Client`
## 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:
### 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]`
@@ -27,4 +28,4 @@ print(client.stop_by_id("A=1@O=Offenbach (Main)-Zentrum Marktplatz\/Frankf. Stra
* [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]`
* [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.