Skip to content

Commit

Permalink
Merge pull request #79 from zaanposni/release/2.2.0
Browse files Browse the repository at this point in the history
Release/2.2.0
  • Loading branch information
zaanposni authored Jun 16, 2024
2 parents 4e4ce18 + ceffd86 commit e352d19
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 48 deletions.
26 changes: 26 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ for dep in deps:
print(dep) # [11:47] [RB17]: Stuttgart Hauptbahnhof (oben) - Pforzheim Hauptbahnhof
```

- Detect cancellations in upcoming departures/arrivals:

```python
from vvspy import get_departures
from vvspy.enums import Station

arrivals = get_departures(Station.VAIHINGEN, limit=5)

for arrival in arrivals:
if arrival.cancelled:
print(f"Alarm! The train at {arrival.real_datetime} has been cancelled!")
# Check arrival.stop_infos and arrival.line_infos for more information
```

- Get complete trip info between two stations (including interchanges):

```python
Expand Down Expand Up @@ -65,6 +79,18 @@ for dep in deps:
print(f"Departure of S4 at {dep.real_datetime}")
```

- Filter for specific platforms:

```python
from vvspy import get_departures
from vvspy.enums import Station

deps = get_departures(Station.HAUPTBAHNHOF__TIEF)
for dep in deps:
if dep.platform == "101":
print(f"Departure of {dep.serving_line.number} to {dep.serving_line.direction} on {dep.platform_name} at {dep.real_datetime}")
```

### Get your station id

See: [#64][station_id_issue_url]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="vvspy",
version="2.1.0",
version="2.2.0",
license="MIT",
description="API Wrapper for VVS (Verkehrsverbund Stuttgart)",
author="zaanposni",
Expand Down
98 changes: 54 additions & 44 deletions vvspy/models/arrival.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,57 @@
class Arrival:
r"""
Arrival object from a arrival request of one station.
Arrival object from a arrival request of one station.
Attributes
-----------
Attributes
-----------
raw :class:`dict`
Raw dict received by the API.
stop_id :class:`str`
Station_id of the arrival.
cancelled :class:`bool`
If the arrival is cancelled.
realtime_status :class:`str`
Realtime status of the arrival.
x :class:`str`
Coordinates of the station.
y :class:`str`
Coordinates of the station.
map_name :class:`str`
Map name the API works on.
area :class:`str`
The area of the station (unsure atm)
platform :class:`str`
Platform / track of the arrival.
platform_name :class:`str`
name of the platform.
stop_name :class:`str`
name of the station.
name_wo :class:`str`
name of the station.
countdown :class:`int`
minutes until arrival.
datetime :class:`datetime.datetime`
Planned arrival datetime.
real_datetime :class:`datetime.datetime`
Estimated arrival datetime (equal to ``self.datetime`` if no realtime data is available).
delay :class:`int`
Delay of arrival in minutes.
serving_line :class:`ServingLine`
line of the incoming arrival.
operator :class:`LineOperator`
Operator of the incoming arrival.
stop_infos Optional[:class:`dict`]
All related info to the station (e.g. maintenance work).
line_infos Optional[:class:`dict`]
All related info to the station (e.g. maintenance work).
"""

raw :class:`dict`
Raw dict received by the API.
stop_id :class:`str`
Station_id of the arrival.
x :class:`str`
Coordinates of the station.
y :class:`str`
Coordinates of the station.
map_name :class:`str`
Map name the API works on.
area :class:`str`
The area of the station (unsure atm)
platform :class:`str`
Platform / track of the arrival.
platform_name :class:`str`
name of the platform.
stop_name :class:`str`
name of the station.
name_wo :class:`str`
name of the station.
countdown :class:`int`
minutes until arrival.
datetime :class:`datetime.datetime`
Planned arrival datetime.
real_datetime :class:`datetime.datetime`
Estimated arrival datetime (equal to ``self.datetime`` if no realtime data is available).
delay :class:`int`
Delay of arrival in minutes.
serving_line :class:`ServingLine`
line of the incoming arrival.
operator :class:`LineOperator`
Operator of the incoming arrival.
stop_infos Optional[:class:`dict`]
All related info to the station (e.g. maintenance work).
line_infos Optional[:class:`dict`]
All related info to the station (e.g. maintenance work).
"""

def __init__(self, **kwargs):
self.stop_id = kwargs.get("stopID")
self.realtime_status = kwargs.get("realtimeStatus")
self.cancelled = self.realtime_status == "ARRIVAL_CANCELLED"
self.x = kwargs.get("x")
self.y = kwargs.get("y")
self.map_name = kwargs.get("mapName")
Expand All @@ -70,7 +76,7 @@ def __init__(self, **kwargs):
month=int(dt.get("month", datetime.now().month)),
day=int(dt.get("day", datetime.now().day)),
hour=int(dt.get("hour", datetime.now().hour)),
minute=int(dt.get("minute", datetime.now().minute))
minute=int(dt.get("minute", datetime.now().minute)),
)
except ValueError:
pass
Expand All @@ -84,7 +90,7 @@ def __init__(self, **kwargs):
month=int(r_dt.get("month", datetime.now().month)),
day=int(r_dt.get("day", datetime.now().day)),
hour=int(r_dt.get("hour", datetime.now().hour)),
minute=int(r_dt.get("minute", datetime.now().minute))
minute=int(r_dt.get("minute", datetime.now().minute)),
)
except ValueError:
pass
Expand All @@ -101,7 +107,11 @@ def __init__(self, **kwargs):
self.line_infos = kwargs.get("lineInfos")

def __str__(self):
pre = "[Delayed] " if self.delay else ""
pre = ""
if self.delay:
pre = "[Delayed] "
if self.cancelled:
pre = "[Cancelled] "
if self.real_datetime.date() == datetime.now().date():
return f"{pre}[{str(self.real_datetime.strftime('%H:%M'))}] {self.serving_line}"
return f"{pre}[{str(self.real_datetime)}] {self.serving_line}"
16 changes: 13 additions & 3 deletions vvspy/models/departure.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class Departure:
Raw dict received by the API.
stop_id :class:`str`
Station_id of the departure.
cancelled :class:`bool`
If the departure is cancelled.
realtime_status :class:`str`
Realtime status of the departure.
x :class:`str`
Coordinates of the station.
y :class:`str`
Expand Down Expand Up @@ -54,6 +58,8 @@ def __init__(self, **kwargs):
self.stop_id = kwargs.get("stopID")
self.x = kwargs.get("x")
self.y = kwargs.get("y")
self.realtime_status = kwargs.get("realtimeStatus")
self.cancelled = self.realtime_status == "DEPARTURE_CANCELLED"
self.map_name = kwargs.get("mapName")
self.area = kwargs.get("area")
self.platform = kwargs.get("platform")
Expand All @@ -70,7 +76,7 @@ def __init__(self, **kwargs):
month=int(dt.get("month", datetime.now().month)),
day=int(dt.get("day", datetime.now().day)),
hour=int(dt.get("hour", datetime.now().hour)),
minute=int(dt.get("minute", datetime.now().minute))
minute=int(dt.get("minute", datetime.now().minute)),
)
except ValueError:
pass
Expand All @@ -84,7 +90,7 @@ def __init__(self, **kwargs):
month=int(r_dt.get("month", datetime.now().month)),
day=int(r_dt.get("day", datetime.now().day)),
hour=int(r_dt.get("hour", datetime.now().hour)),
minute=int(r_dt.get("minute", datetime.now().minute))
minute=int(r_dt.get("minute", datetime.now().minute)),
)
except ValueError:
pass
Expand All @@ -101,7 +107,11 @@ def __init__(self, **kwargs):
self.line_infos = kwargs.get("lineInfos")

def __str__(self):
pre = "[Delayed] " if self.delay else ""
pre = ""
if self.delay:
pre = "[Delayed] "
if self.cancelled:
pre = "[Cancelled] "
if self.real_datetime.date() == datetime.now().date():
return f"{pre}[{str(self.real_datetime.strftime('%H:%M'))}] {self.serving_line}"
return f"{pre}[{str(self.real_datetime)}] {self.serving_line}"

0 comments on commit e352d19

Please sign in to comment.