diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 09b9164..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1 +0,0 @@ -include iceportal_apis/mocking/sample_data/*.json \ No newline at end of file diff --git a/README.md b/README.md index 752a6a2..e4ebc80 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,6 @@ No longer actively developed in favor of the [onboardAPIs](https://github.com/fe --- - [![PyPI version](https://badge.fury.io/py/iceportal_apis.svg)](https://pypi.org/project/iceportal-apis) [![PyPI-Versions](https://img.shields.io/pypi/pyversions/iceportal-apis)](https://pypi.org/project/iceportal-apis) [![GitHub](https://img.shields.io/badge/license-MIT-green)](https://github.com/felix-zenk/iceportal-apis/blob/main/LICENSE) @@ -19,20 +18,13 @@ This is an unofficial project and not supported by [`Deutsche Bahn AG`](https:// > Note, that this module will only work correctly while you are on a train and connected to its WiFi-Hotspot. -# - ### Installation * Available on PyPI ```shell $ python -m pip install iceportal_apis ``` -# - ### Usage -> ~~Example code is available in the file [`example.py`](https://github.com/felix-zenk/iceportal-apis/blob/main/samples/example.py) and other files in [`samples`](https://github.com/felix-zenk/iceportal-apis/blob/main/samples).~~ -> -> ~~The basic usage consists of requesting new data from the api, then processing it with the modules functions.~~ ```python import iceportal_apis as ipa @@ -50,40 +42,20 @@ while True: . . . ``` -# - ### License > **This software is distributed under the MIT License, please see [`LICENSE`](https://github.com/felix-zenk/iceportal-apis/blob/main/LICENSE) for detailed information.** -# - -###
API documentation
+### API documentation #### 1. Status API The Status API is available at [https://iceportal.de/api1/rs/status](https://iceportal.de/api1/rs/status) -~~A sample response can be found at:~~ -```python -# deprecated -``` - #### 2. Trip API The Trip API is available at [https://iceportal.de/api1/rs/tripInfo/trip](https://iceportal.de/api1/rs/tripInfo/trip) -~~A sample response can be found at:~~ -```python -# deprecated -``` - #### 3. Connections API The Connecting trains API can be found at [https://iceportal.de/api1/rs/tripInfo/connection/{eva_number}](https://iceportal.de/api1/rs/tripInfo/connection/8000000_00) -~~A sample response can be found at:~~ -```python -# deprecated -``` - - #### 4. Other APIs These are other APIs I discovered but didn't investigate in: @@ -93,4 +65,6 @@ These are other APIs I discovered but didn't investigate in: 4.3. [https://iceportal.de/api1/rs/configs/cities](https://iceportal.de/api1/rs/configs/cities) -# +4.4. [https://iceportal.de/bap/api/availabilities](https://iceportal.de/bap/api/availabilities) + +4.5. [https://iceportal.de/bap/api/bap-service-status](https://iceportal.de/bap/api/bap-service-status) diff --git a/iceportal_apis/__init__.py b/iceportal_apis/__init__.py index 39c59ce..0ffb93d 100644 --- a/iceportal_apis/__init__.py +++ b/iceportal_apis/__init__.py @@ -6,10 +6,10 @@ from typing import Union, Any, List, Tuple, Dict from datetime import datetime, timedelta -from onboardapis.utils.conversions import ms_to_kmh from onboardapis import Vehicle -from onboardapis.trains import Station as OAStation, ConnectingTrain -from onboardapis.trains.germany.db import ICEPortal +from onboardapis.units import kmh +from onboardapis.train import TrainStation as OAStation, ConnectingTrain +from onboardapis.train.de.db import ICEPortal from .types import (TrainType, WagonClass, InterfaceStatus, Internet) from .exceptions import (ApiException, NetworkException, NotInFutureException, NotAvailableException, @@ -17,16 +17,12 @@ import warnings warnings.warn( - "This package is no longer maintained in favor of the 'onboardapis' package https://pypi.org/projects/onboardapis.", + "This package is no longer maintained in favor of the " + "'onboardapis' package https://pypi.org/projects/onboardapis." + "At this point iceportal-apis also is just a wrapper around onboardapis.", DeprecationWarning ) -###################################### -__author__ = 'Felix Zenk' -__email__ = 'felix.zenk@web.de' -__version__ = '2.0.2' -###################################### - def _ensure_not_none(param: Any) -> Any: """ @@ -72,21 +68,21 @@ def __repr__(self) -> str: class Train(Vehicle): - def __init__(self, auto_refresh: bool = False, test_mode: bool = False, dynamic_simulation: bool = False) -> None: - if test_mode or dynamic_simulation: - raise NotImplementedError("Test mode and dynamic simulation are not supported anymore.") + __oa: ICEPortal + + def __init__(self, *args, **kwargs) -> None: super().__init__() self.__oa = ICEPortal() self.__oa.init() def __str__(self) -> str: - return "<"+self.get_train_type().name+" "+self.get_trip_id()+" -> "+self.get_final_station().name+">" + return "<%s %s -> %s>" % (self.get_train_type().name, self.get_trip_id(), self.get_next_station().name) def get_speed(self) -> float: """ Gets the current speed of the train in kilometers/hour. """ - return ms_to_kmh(self.__oa.speed) + return kmh(ms=self.__oa.speed) def get_train_type(self) -> TrainType: """ @@ -100,34 +96,36 @@ def get_wagon_class(self) -> WagonClass: """ Gets the wagon class (can be inaccurate for wagons next to another class). """ - return WagonClass.__members__[self.__oa.wagon_class()] \ - if self.__oa.wagon_class() in WagonClass.__members__.keys() \ + return ( + WagonClass.__members__[self.__oa.wagon_class] # type: str + if self.__oa.wagon_class in WagonClass.__members__.keys() else WagonClass.UNKNOWN + ) def get_internet_status(self) -> Internet: """ Gets the current internet status / (speed) """ - return _convert_to_internet_status(self.__oa.internet_connection()[0]) + return _convert_to_internet_status(self.__oa.internet_status) def get_next_internet_status(self) -> Internet: """ Gets the next internet status / (speed) """ - return _convert_to_internet_status(_ensure_not_none(self.__oa.internet_connection()[1])) + return _convert_to_internet_status(_ensure_not_none(self.__oa.next_internet_status)) def get_time_until_internet_change(self) -> timedelta: """ Gets the time until the network status changes """ - return timedelta(seconds=int(_ensure_not_none(self.__oa.internet_connection()[2]))) + return _ensure_not_none(self.__oa.internet_status_change) def has_bap_service(self) -> bool: """ Whether this train offers ordering food from the passengers seat :return: Whether this train provides bap service or not """ - return self.__oa.has_bap() + return self.__oa.has_bap def get_latitude(self) -> float: """ @@ -157,7 +155,7 @@ def get_trip_id(self) -> str: """ Gets the ID of the trip """ - return self.__oa.number + return self.__oa.line_number def get_next_station(self) -> Station: """ @@ -169,11 +167,7 @@ def get_last_station(self) -> Station: """ Gets the last station. """ - idx_last_station = list(self.__oa.stations.values()).index(self.__oa.current_station) - 1 - if idx_last_station < 0: - idx_last_station = 0 - id_last_station = list(self.__oa.stations.keys())[idx_last_station] - station = self.__oa.stations.get(id_last_station) + station = self.__oa.stations[max(0, self.__oa.stations.index(self.__oa.current_station) - 1)] return Station(station.id, station.name) def get_final_station(self) -> Station: @@ -186,15 +180,15 @@ def get_all_stations(self) -> List[Station]: """ Gets all stations for this trip. """ - return list([ - Station(station.id, station.name) for station in self.__oa.stations.values() - ]) + return [ + Station(station.id, station.name) for station in self.__oa.stations + ] def get_arrival_time(self, station: Station) -> datetime: """ Gets the arrival time at a specific station. """ - return self.__oa.stations.get(station.eva_number).arrival.actual + return self.__oa.stations_dict.get(station.eva_number).arrival.actual def get_time_until_arrival(self, station: Station) -> timedelta: """Gets the time until the arrival at a specific station. @@ -206,7 +200,7 @@ def get_departure_time(self, station: Station) -> datetime: """ Gets the departure time at a specific station. """ - return self.__oa.stations.get(station.eva_number).departure.actual + return self.__oa.stations_dict.get(station.eva_number).departure.actual def get_time_until_departure(self, station: Station) -> timedelta: """ @@ -219,22 +213,22 @@ def get_platform(self, station: Station) -> str: """ Gets the trains arrival platform for a specific station """ - return self.__oa.stations.get(station.eva_number).platform.actual + return self.__oa.stations_dict.get(station.eva_number).platform.actual def get_delay_at(self, station: Station) -> timedelta: """ Gets the delay at a station """ return ( - self.__oa.stations.get(station.eva_number).arrival.actual - - self.__oa.stations.get(station.eva_number).arrival.scheduled + self.__oa.stations_dict.get(station.eva_number).arrival.actual + - self.__oa.stations_dict.get(station.eva_number).arrival.scheduled ) def get_current_delay(self) -> timedelta: """ Gets the current delay """ - return timedelta(seconds=self.__oa.delay) + return self.__oa.delay def is_delayed(self) -> bool: """ @@ -246,7 +240,7 @@ def get_delay_reasons_at(self, station: Station) -> List[str]: """ Gets the delay reasons for a specific station """ - return self.__oa.all_delay_reasons().get(station.eva_number, []) + return self.__oa.all_delay_reasons.get(station.eva_number, []) def get_current_delay_reasons(self) -> List[str]: """ @@ -258,20 +252,20 @@ def get_station_position(self, station: Station) -> Tuple[float, float]: """ Gets the position of a specific station """ - pos = self.__oa.stations.get(station.eva_number).position + pos = self.__oa.stations_dict.get(station.eva_number).position return pos.latitude, pos.longitude def get_station_distance(self, station: Station) -> float: """ Calculates the distance to a specific station and returns it in meters """ - return self.__oa.calculate_distance(self.__oa.stations.get(station.eva_number)) + return self.__oa.calculate_distance(self.__oa.stations_dict.get(station.eva_number)) def get_connections(self, station: Station) -> List[ConnectingTrain]: """ Returns the connecting trains from a specific station """ - return self.__oa.stations.get(station.eva_number).connections + return self.__oa.stations_dict.get(station.eva_number).connections def get_all_connections(self) -> Dict[str, List[ConnectingTrain]]: """ @@ -279,8 +273,8 @@ def get_all_connections(self) -> Dict[str, List[ConnectingTrain]]: (usually every station except for the first one) """ return { - station_id: self.__oa.stations.get(station.id).connections - for station_id, station in self.__oa.stations.items() + station_id: self.__oa.stations_dict.get(station.id).connections + for station_id, station in self.__oa.stations_dict.items() } def get_connections_info(self, station) -> List[Dict[str, Union[str, Station, datetime]]]: @@ -292,7 +286,7 @@ def get_connections_info(self, station) -> List[Dict[str, Union[str, Station, da """ return list([ { - 'trainName': f"{connection.train_type} {connection.line_number}", + 'trainName': f"{connection.vehicle_type} {connection.line_number}", 'finalStation': connection.destination, 'departure': ( connection.departure.actual diff --git a/requirements.txt b/requirements.txt index 4b63317..0e2fb63 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -onboardapis>=1.2.3 +onboardapis>=2.0.0,<3 \ No newline at end of file diff --git a/setup.py b/setup.py index e3afedf..c1163d6 100644 --- a/setup.py +++ b/setup.py @@ -1,26 +1,20 @@ -import setuptools -from iceportal_apis import __version__, __author__, __email__ +from pathlib import Path +from setuptools import setup, find_packages -with open("README.md", "r") as fh: - long_description = fh.read() - -include_files = {'iceportal_apis': ['*.json', 'mocking/sample_data/*.json']} - -setuptools.setup( +setup( name="iceportal_apis", - version=__version__, - author=__author__, - author_email=__email__, + version='2.0.3', + author='Felix Zenk', + author_email='felix.zenk@web.de', description="A module for interacting with the Deutsche Bahn onboard APIs", - long_description=long_description, + long_description=Path('README.md').read_text(encoding='utf-8'), long_description_content_type="text/markdown", url="https://github.com/felix-zenk/iceportal-apis", project_urls={ "Bug Reports": "https://github.com/felix-zenk/iceportal-apis/issues/new?labels=bug&template=bug_report.md&title=%5BBUG%5D%3A+", "Source": "https://github.com/felix-zenk/iceportal-apis", }, - packages=setuptools.find_packages(), - include_package_data=True, + packages=find_packages(include=['iceportal_apis', 'iceportal_apis.*']), license='MIT', classifiers=[ 'License :: OSI Approved :: MIT License', @@ -36,5 +30,5 @@ "Topic :: Internet :: WWW/HTTP :: Dynamic Content", 'Topic :: Utilities' ], - python_requires='>=3.7.2', -) \ No newline at end of file + python_requires='>=3.8', +)