11 Commits

Author SHA1 Message Date
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
9 changed files with 90 additions and 56 deletions

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

@@ -21,14 +21,10 @@ trip = client.trip_find(origin_id=origin.id, dest_id=destination.id)
"""
__name__ = "pyrmv"
__version__ = "0.3.1"
__version__ = "0.3.5"
__license__ = "MIT License"
__author__ = "Profitroll"
from . import raw
from . import const
from . import enums
from . import errors
from . import utility
from . import const, enums, errors, raw, utility
from .classes import *
from .classes.Client import Client
from .classes.Client import Client

View File

@@ -3,17 +3,23 @@ from pyrmv.classes.Message import Message
class LineArrival():
def __init__(self, data, client):
def __init__(self, data, client, retrieve_stops: bool = True):
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))
if "Messages" in data:
self.messages.extend(
Message(message) for message in data["Messages"]["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"]
if retrieve_stops:
self.stop = client.stop_by_id(self.stop_id)
else:
self.stop = 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")
@@ -28,18 +34,23 @@ class LineArrival():
class LineDeparture():
def __init__(self, data, client):
def __init__(self, data, client, retrieve_stops: bool = True):
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))
if "Messages" in data:
self.messages.extend(
Message(message) for message in data["Messages"]["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)
if retrieve_stops:
self.stop = client.stop_by_id(self.stop_id)
else:
self.stop = None
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):
@@ -54,10 +65,12 @@ class LineDeparture():
class BoardArrival(list):
def __init__(self, data: dict, client):
def __init__(self, data: dict, client, retrieve_stops: bool = True):
super().__init__([])
if "Arrival" not in data:
return
for line in data["Arrival"]:
self.append(LineArrival(line, client))
self.append(LineArrival(line, client, retrieve_stops=retrieve_stops))
def __str__(self) -> str:
lines = []
@@ -67,10 +80,12 @@ class BoardArrival(list):
class BoardDeparture(list):
def __init__(self, data: dict, client):
def __init__(self, data: dict, client, retrieve_stops: bool = True):
super().__init__([])
if "Departure" not in data:
return
for line in data["Departure"]:
self.append(LineDeparture(line, client))
self.append(LineDeparture(line, client, retrieve_stops=retrieve_stops))
def __str__(self) -> str:
lines = []

View File

@@ -81,6 +81,7 @@ class Client():
lines: Union[str, list, None] = None,
passlist: bool = False,
board_type: Literal[BoardArrivalType.ARR, BoardArrivalType.ARR_EQUIVS, BoardArrivalType.ARR_MAST, BoardArrivalType.ARR_STATION] = BoardArrivalType.ARR,
retrieve_stops: bool = True
) -> BoardArrival:
"""Method returns a board with arriving transport.
@@ -98,6 +99,7 @@ class Client():
* lines (`Union[str, list]`, **optional**): Only journeys running the given line are part of the result. To filter multiple lines, provide a list or separate the codes by comma or provide a list. If the line should not be part of the be trip, negate it by putting ! in front of it. Defaults to `None`.
* passlist (`bool`, **optional**): Include a list of all passed waystops. Defaults to `False`.
* board_type (`Union[BoardArrivalType.ARR, BoardArrivalType.ARR_EQUIVS, BoardArrivalType.ARR_MAST, BoardArrivalType.ARR_STATION]`, optional): Set the station arrival board type to be used. Defaults to `BoardArrivalType.ARR`.
* retrieve_stops (`bool`, **optional**): Whether the stops should be retrieved as a `Stop` objects. Using `False` will drastically increase processing speed and decrease number of requests made (good for low access_key rate limit). Defaults to `True`.
### Returns:
* BoardArrival: Instance of `BoardArrival` object.
@@ -123,7 +125,7 @@ class Client():
find_exception(board_raw)
return BoardArrival(board_raw, self)
return BoardArrival(board_raw, self, retrieve_stops=retrieve_stops)
def board_departure(self,
id: Union[str, None] = None,
@@ -137,6 +139,7 @@ class Client():
lines: Union[str, list, None] = None,
passlist: bool = False,
board_type: Literal[BoardDepartureType.DEP, BoardDepartureType.DEP_EQUIVS, BoardDepartureType.DEP_MAST, BoardDepartureType.DEP_STATION] = BoardDepartureType.DEP,
retrieve_stops: bool = True
) -> BoardDeparture:
"""Method returns a board with departing transport.
@@ -154,6 +157,7 @@ class Client():
* lines (`Union[str, list]`, **optional**): Only journeys running the given line are part of the result. To filter multiple lines, provide a list or separate the codes by comma or provide a list. If the line should not be part of the be trip, negate it by putting ! in front of it. Defaults to `None`.
* passlist (`bool`, **optional**): Include a list of all passed waystops. Defaults to `False`.
* board_type (`Union[BoardDepartureType.DEP, BoardDepartureType.DEP_EQUIVS, BoardDepartureType.DEP_MAST, BoardDepartureType.DEP_STATION]`, optional): Set the station departure board type to be used. Defaults to `BoardDepartureType.DEP`.
* retrieve_stops (`bool`, **optional**): Whether the stops should be retrieved as a `Stop` objects. Using `False` will drastically increase processing speed and decrease number of requests made (good for low access_key rate limit). Defaults to `True`.
### Returns:
* BoardDeparture: Instance of `BoardDeparture` object.
@@ -179,7 +183,7 @@ class Client():
find_exception(board_raw)
return BoardDeparture(board_raw, self)
return BoardDeparture(board_raw, self, retrieve_stops=retrieve_stops)
def him_search(self,
date_begin: Union[str, datetime, None] = None,
@@ -297,8 +301,9 @@ class Client():
find_exception(messages_raw)
for message in messages_raw["Message"]:
messages.append(Message(message))
if "Message" in messages_raw:
for message in messages_raw["Message"]:
messages.append(Message(message))
return messages
@@ -398,11 +403,12 @@ class Client():
find_exception(stops_raw)
for stop in stops_raw["stopLocationOrCoordLocation"]:
if "StopLocation" in stop:
stops.append(Stop(stop["StopLocation"]))
elif "CoordLocation" in stop:
stops.append(Stop(stop["CoordLocation"]))
if "stopLocationOrCoordLocation" in stops_raw:
for stop in stops_raw["stopLocationOrCoordLocation"]:
if "StopLocation" in stop:
stops.append(Stop(stop["StopLocation"]))
elif "CoordLocation" in stop:
stops.append(Stop(stop["CoordLocation"]))
return stops
@@ -500,11 +506,12 @@ class Client():
find_exception(stops_raw)
for stop in stops_raw["stopLocationOrCoordLocation"]:
if "StopLocation" in stop:
stops.append(Stop(stop["StopLocation"]))
elif "CoordLocation" in stop:
stops.append(Stop(stop["CoordLocation"]))
if "stopLocationOrCoordLocation" in stops_raw:
for stop in stops_raw["stopLocationOrCoordLocation"]:
if "StopLocation" in stop:
stops.append(Stop(stop["StopLocation"]))
elif "CoordLocation" in stop:
stops.append(Stop(stop["CoordLocation"]))
return stops
@@ -693,8 +700,9 @@ class Client():
find_exception(trips_raw)
for trip in trips_raw["Trip"]:
trips.append(Trip(trip))
if "Trip" in trips_raw:
for trip in trips_raw["Trip"]:
trips.append(Trip(trip))
return trips
@@ -766,7 +774,8 @@ class Client():
find_exception(trips_raw)
for trip in trips_raw["Trip"]:
trips.append(Trip(trip))
if "Trip" in trips_raw:
for trip in trips_raw["Trip"]:
trips.append(Trip(trip))
return trips

View File

@@ -11,11 +11,12 @@ class Journey():
self.direction_flag = data["Directions"]["Direction"][0]["flag"]
self.messages = []
for stop in data["Stops"]["Stop"]:
self.stops.append(Stop(stop))
self.stops.extend(Stop(stop) for stop in data["Stops"]["Stop"])
for message in data["Messages"]["Message"]:
self.messages.append(Message(message))
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})"

View File

@@ -61,7 +61,7 @@ class Message():
self.text = data["text"]
self.company = data["company"]
self.category = data["category"]
self.priority = data["priority"]
self.priority = None if "priority" not in data else data["priority"]
self.products = data["products"]
self.icon = data["icon"]
self.time_start = datetime.strptime(data["sTime"], "%H:%M:%S")

View File

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

View File

@@ -2,7 +2,7 @@ from setuptools import setup
setup(
name="pyrmv",
version="0.3.1",
version="0.3.5",
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## Requirements\n\n* RMV API key (Get it [here](https://opendata.rmv.de/site/start.html))\n* Python3 (Tested versions are 3.7.9 and 3.9.13)\n* git (Only for installation from source)\n\n## Installation\n\nIf you have everything listed in [requirements](#requirements), then let's begin.\n\n### Variant 1\n\n1. `python -m pip install pyrmv`\n\n### Variant 2\n\n1. `git clone https://git.end-play.xyz/profitroll/PythonRMV.git`\n2. `cd PythonRMV`\n3. `python setup.py install`\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?](#why-are-there-raw-versions-and-formatted-ones)\n* [Some methods work slightly different](#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### 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\n### General\n\n* [ ] Docs in Wiki\n* [ ] Tickets",
@@ -21,13 +21,9 @@ setup(
"pyrmv.enums",
"pyrmv.errors",
"pyrmv.utility",
"pyrmv.classes"
],
install_requires=[
"requests",
"xmltodict",
"isodate"
"pyrmv.classes",
],
install_requires=["requests", "xmltodict", "isodate"],
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
@@ -35,6 +31,6 @@ setup(
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Utilities"
]
)
"Topic :: Utilities",
],
)

View File

@@ -1,6 +1,6 @@
from datetime import datetime, timedelta
from os import makedirs
from typing import Any, Union
from typing import Any
from ujson import loads, dumps, JSONDecodeError
from test_colors import *
@@ -72,7 +72,7 @@ test("raw_trip_find", pyrmv.raw.trip_find(key, originCoordLat="50.084659", origi
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("board_departure", client.board_departure("A=1@O=Frankfurt (Main) Taunusanlage@X=8668765@Y=50113478@U=80@L=3000011@", journeys_max=5, retrieve_stops=False))
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))