Code Monkey home page Code Monkey logo

vvspy's Introduction

VVS API Wrapper

Checkup status Checkup status

Fully object-oriented library to integrate the VVS API into your project.

Installation

Python 3.6 or higher required

pip install vvspy

Examples

  • Detect delay in upcoming departures:
from vvspy import get_departures

deps = get_departures("5006115", limit=3)  # Stuttgart main station
for dep in deps:
    if dep.delay > 0:
        print("Alarm! Delay detected.")
        print(dep)  # [Delayed] [11:47] [RB17]: Stuttgart Hauptbahnhof (oben) - Pforzheim Hauptbahnhof

    else:
        print("Train on time")
        print(dep)  # [11:47] [RB17]: Stuttgart Hauptbahnhof (oben) - Pforzheim Hauptbahnhof
  • Get complete trip info between two stations (including interchanges):
from vvspy import get_trip  # also usable: get_trips

trip = get_trip("5000355", "5005600")  # Stuttgart main station

print(f"Duration: {trip.duration / 60} minutes")
for connection in trip.connections:
    print(f"From: {connection.origin.name} - To: {connection.destination.name}")
# Output:
Duration: 58 minutes
From: Wallgraben - To: Hauptbf (A.-Klett-Pl.)
From: Hauptbf (Arnulf-Klett-Platz) - To: Stuttgart Hauptbahnhof (tief)
From: Stuttgart Hauptbahnhof (tief) - To: Marbach (N)
From: Marbach (N) Bf - To: Murr Hardtlinde
  • Filter for specific lines:
from vvspy import get_departures

deps = get_departures("5006118")  # Stuttgart main station (lower)
for dep in deps:
    if dep.serving_line.symbol == "S4":
        print(f"Departure of S4 at {dep.real_datetime}")

Get your station id

See: #12 (comment)

Features

  • full customizable requests and parameters

  • parsing all available info into result obj

  • Well tested and maintained

  • Departures, Arrivals, Trips, Station info, Upcoming events, Maintenance work

  • See issues/projects on GitHub for upcoming features

Contributors

Projects using vvspy

License:

This project is licensed under MIT.

vvspy's People

Contributors

arpiix avatar mhorst00 avatar monkmitrad avatar zaanposni avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

vvspy's Issues

[Feature] Add more tests

Summarize the feature
Currently, this project's test coverage is only 60%. Especially get_depatures(), get_trips, and get_arrivals() needs to be tested. Additionally, all the data classes should be tested as well.

Example of the feature
None

Additional context
None

missing delay data

Describe the bug
A clear and concise description of what the bug is.

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Code fragment
Let us see the important code sample that fails.

Additional context
Add any other context about the problem here.

[BUG] get_trips triggers an exception when connections do not have a duration set

Describe the bug
The method get_trips triggers an exception upon retrieving a trip that contains a connection that does not have the connection.duration attribute set.

Apparently, the VVS API does not set the duration property in case a connection takes less than a minute, i.e. the duration would be 0. This is at least what I assume to be reason for not adding the duration.

Expected behavior
The request should not fail. If no duration is given, it probably is 0 and thus does not need to be part of the final sum.

Proof of Concept
The following request is one that triggers the exception. One part of the trip contains a connection with only one stop, taking less than a minute.

from vvspy import get_trips
from datetime import datetime

trip = get_trips("de:08111:341", "de:08111:6118", trip_date=datetime(2022, 8, 1, 10, 15, 0, 0))
print(trip)

Code fragment

The problematic code can be found in https://github.com/zaanposni/vvspy/blob/master/vvspy/obj/trip.py#L33:

    def __init__(self, **kwargs):
        self.connections = []
        for connection in kwargs.get("legs", []):
            self.connections.append(Connection(**connection))

        self.duration = sum([x.duration for x in self.connections])

Suggestion
It has to be checked whether the duration attribute exists. If it does not exist, (I assume that) it is equal to 0 and therefore can be left out.

        self.duration = sum([x.duration for x in self.connections if x.duration])

release library

after #5, #6, #7 do:

  • bump version to 1.0.0
  • set status to Development Status :: 5 - Production/Stable

[Feature] Add a package manager and `pyproject.toml`

Summarize the feature
The current setup with setup.py and all the other settings files is not quite convenient. Additionally, the packages within the requierements.txt are not correctly checked for compatibility. For that, I recommend using Poetry or Pipenv.

Further, I recommend switching most of the configurations to the pyproject.toml (docs).

Example of the feature
Using Poetry, it is possible to easily manage packages using poetry add and poetry install. It is also possible to define different groups like dev or docs so that you can exclude not necessary packages.

Additional context
None

[Feature] Add logging package

Summarize the feature
To easier determine errors, it would be handy if a logging package would be used. For that, I recommend Loguru.

Example of the feature
Loguru enables the developer to just import from loguru import logger and then use logging levels like debug, info, and error. In comparison to the default logger, Loguru logs are already nicely formatted.

Additional context
As an alternative, the built-in logging package could be used.

[Feature] Add Codecov Reports

Summarize the feature
To ensure the functionality, the test coverage should be at least 80%. I recommend using Codecov.

Additional context
Using pytest, pytest-cov, and GitHub Actions, this can be easily achieved. An example configuration can be found here.

Filter canceled trains

Hi,
I'm using VVSPY since 1 year as HomaAssistant integration and I'm very happy. I'm requesting all departures for station 'Universität' every 2 mins.
On Thursday, 16.11.2023 the S-Bahn did not operate at all in the morning due to union strike. My request with vvspy received still all S-Bahn trains - with zero delay :-), which was obviousely wrong.
The VVS website did not show the S-Bahn trains.
Is there an additional filter, i can apply for canceled trains?

Kind Regards & Thanks for your great work!
Ralf

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.