From eb9a043c342d08d800f75acc6e0324a2e24da05c Mon Sep 17 00:00:00 2001 From: profitroll Date: Sun, 19 Nov 2023 12:19:31 +0100 Subject: [PATCH] Probably a fix for #2 --- pyrmv/__init__.py | 10 +++------- pyrmv/classes/Board.py | 12 ++++++++---- pyrmv/classes/Journey.py | 9 +++++---- pyrmv/classes/Message.py | 2 +- requirements.txt | 6 +++--- setup.py | 16 ++++++---------- 6 files changed, 26 insertions(+), 29 deletions(-) diff --git a/pyrmv/__init__.py b/pyrmv/__init__.py index 87e4d99..b107229 100644 --- a/pyrmv/__init__.py +++ b/pyrmv/__init__.py @@ -21,14 +21,10 @@ trip = client.trip_find(origin_id=origin.id, dest_id=destination.id) """ __name__ = "pyrmv" -__version__ = "0.3.4" +__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 \ No newline at end of file +from .classes.Client import Client diff --git a/pyrmv/classes/Board.py b/pyrmv/classes/Board.py index 3c16427..70d3429 100644 --- a/pyrmv/classes/Board.py +++ b/pyrmv/classes/Board.py @@ -7,8 +7,10 @@ class LineArrival(): 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"] @@ -36,8 +38,10 @@ class LineDeparture(): 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"] diff --git a/pyrmv/classes/Journey.py b/pyrmv/classes/Journey.py index 347a355..2f08d7e 100644 --- a/pyrmv/classes/Journey.py +++ b/pyrmv/classes/Journey.py @@ -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})" \ No newline at end of file diff --git a/pyrmv/classes/Message.py b/pyrmv/classes/Message.py index 0dbb55d..f93754d 100644 --- a/pyrmv/classes/Message.py +++ b/pyrmv/classes/Message.py @@ -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") diff --git a/requirements.txt b/requirements.txt index c69e0e3..38ad334 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -requests -xmltodict -isodate \ No newline at end of file +requests~=2.31.0 +xmltodict~=0.13.0 +isodate~=0.6.1 \ No newline at end of file diff --git a/setup.py b/setup.py index 25fbf70..77cff13 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup setup( name="pyrmv", - version="0.3.4", + 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" - ] -) \ No newline at end of file + "Topic :: Utilities", + ], +)