Coder Social home page Coder Social logo

offenesdresden / dvbpy Goto Github PK

View Code? Open in Web Editor NEW
46.0 8.0 7.0 962 KB

🚋 Query Dresden's public transport system for current bus- and tramstop data in python

Home Page: https://pypi.org/project/dvb/

License: MIT License

Python 99.75% Shell 0.25%
dvb vvo dresden public-transportation

dvbpy's Introduction

dvbpy

An unofficial python module giving you a few options to query a collection of publicly accessible API methods for Dresden's public transport system.

Want something like this for another language, look no further 🙂

The documentation is located here.

Get dvbpy from PyPi :)

pip install dvb

And then just import it.

import dvb

Monitor a single stop

Monitor a single stop to see every bus or tram leaving this stop after the specified time offset.

import dvb

stop = 'Helmholtzstraße'
time_offset = 0 # how many minutes in the future, 0 for now
num_results = 2
city = 'Dresden'

dvb.monitor(stop, time_offset, num_results, city)
[{
    'line': '85',
    'direction': 'Striesen',
    'arrival': 5
},
{
    'line': '85',
    'direction': 'Löbtau Süd',
    'arrival': 7
}]

You can also call monitor() without city, num_results or time_offset. City will default to Dresden.

Find routes

Query the server for possible routes from one stop to another. Returns multiple possible trips, the bus-/tramlines to be taken, the single stops, their arrival and departure times and their GPS coordinates.

import dvb
import time

origin = 'Zellescher Weg'
city_origin = 'Dresden'
destination = 'Postplatz'
city_destination = 'Dresden'
time = int(time.time()) # a unix timestamp is wanted here
deparr = 'dep'  # set to 'arr' for arrival time, 'dep' for departure time

dvb.route(origin, destination, city_origin, city_destination, time, deparr)
{
    'trips': [{
        'interchange': 0,
        'nodes': [{
            'line': '11',
            'mode': 'Straßenbahn',
            'direction': 'Dresden Bühlau Ullersdorfer Platz',
            'path': [
                [13.745754, 51.02816],
                [13.745848, 51.028393],
                ...
            ],
            'departure': {
                'time': '18:01',
                'stop': 'Zellescher Weg',
                'coords': '13745754,51028160'
            },
            'arrival': {
                'time': '18:14',
                'stop': 'Postplatz',
                'coords': '13733717,51050544'
            }
        }],
        'duration': '00:13',
        'departure': '18:01',
        'arrival': '18:14'
    },
    ...
    }],
    'origin': 'Dresden, Zellescher Weg',
    'destination': 'Dresden, Postplatz'
}

Everything besides origin and destination is optional and only needs to be included if necessary. City for origin and destination defaults to Dresden, time to now and is handled as the departure time.

The path property contains a list consisting of all the coordinates describing the path of this node. Useful for example if you want to draw it on a map.

If you use recommendations for interchanges, each of the nodes (except the last one)in every trip will have a recommendation field. The field will tell where you should enter this route to get an optimal interchange experience. This is of course only if there are any interchanges. The positions are 0 for front, 1 for middle and 2 for back. If there are no recommendations available None is returned.

Find stops by name

Search for a single stop in the network of the DVB.

import dvb

dvb.find('zellesch')
[{
    'name': 'Zellescher Weg',
    'city': 'Dresden',
    'coords': [51.028366, 13.745847]
}]

The fields city and coords are optional as they are not available for every stop. So don't forget to check for their existence first.

[stop for stop in dvb.find('Post') if 'city' in stop if stop['city'] == 'Dresden']

Find other POIs with coordinates

Search for all kinds of POIs inside a given square.

import dvb

southwest_lat = 51.04120
southwest_lng = 13.70106
northeast_lat = 51.04615
northeast_lng = 13.71368

pintypes = 'stop'
# can be poi, platform, rentabike, ticketmachine, parkandride, carsharing or stop

dvb.pins(southwest_lat, southwest_lng, northeast_lat, northeast_lng, pintypes)

pintypes defaults to 'stop' if no other input is given.

[
   {
      "connections":"1:7~8~9~10~11~12",
      "coords":{
         "lat":51.04373256804444,
         "lng":13.70625638110702
      },
      "id":33000143,
      "name":"Saxoniastraße"
   },
   {
      "connections":"2:61~90",
      "coords":{
         "lat":51.04159705545878,
         "lng":13.7053650905211
      },
      "id":33000700,
      "name":"Ebertplatz"
   },
   {
      "connections":"1:6~7~8~9~10~11~12#2:61~63~90~A#3:333",
      "coords":{
         "lat":51.04372841952444,
         "lng":13.703461228676069
      },
      "id":33000144,
      "name":"Tharandter Straße"
   }, ...
]

Look up coordinates for POI

Find the coordinates for a given POI id.

import dvb

dvb.poi_coords(33000755)
{'lat': 51.018745307424005, 'lng': 13.758700156062707}

Address for coordinates - WIP

Look up the address for a given set of coordinates.

import dvb

lat = 51.04373
lng = 13.70320

dvb.address(lat, lng)
{
    'city': u'Dresden',
    'address': u'Kesselsdorfer Straße 1'
}

Other stuff

Stop names in queries are very forgiving. As long as the server sees it as a unique hit, it'll work. 'Helmholtzstraße' finds the same data as 'helmholtzstrasse', 'Nürnberger Platz' = 'nuernbergerplatz' etc.

One last note, be sure not to run whatever it is you're building from inside the network of the TU Dresden. Calls to dvb.route() and dvb.find() will time out. This is unfortunately expected behavior as API calls from these IP ranges are blocked.

dvbpy's People

Contributors

dependabot[bot] avatar dirkonet avatar h4llow3en avatar justusadam avatar kiliankoe avatar lucaswo avatar ubahnverleih 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dvbpy's Issues

Repair dvb.route

Hey
I've seen that you notice that the route is not working anymore. Do you want to fix this bug? I want to work with this module and every time I used it I get a TimeoutError.

Kind regards
JuRolf

Could not find a version that satisfies the requirement

pi@RASPBERRYPI2 ~ $ sudo pip install dvbpy
Collecting dvbpy
  Could not find a version that satisfies the requirement dvbpy (from versions: )
No matching distribution found for dvbpy

Every time when I try to install dvbpy on my Raspberry Pi2

SyntaxError: invalid syntax

import dvb

 File "/Users/balzer82/anaconda/lib/python2.7/site-packages/dvb/dvb.py", line 7
    def monitor(stop, offset=0, limit=10, city='Dresden', *, raw=False):
                                                           ^
SyntaxError: invalid syntax

Cleanup code

There's a few things to be cleaned up. Coords returned as strings, unnecessary request parameters and stuff.

Also catch more exceptions on dictionary creation to prevent possible crashes on badly formatted data.

And what about possibly splitting this up across files? Does that make sense?

catch Value error if no int is returned

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/site-packages/dvb-1.0-py3.5.egg/dvb/dvb.py", line 37, in monitor
  File "/usr/local/lib/python3.5/site-packages/dvb-1.0-py3.5.egg/dvb/dvb.py", line 37, in <listcomp>
ValueError: invalid literal for int() with base 10: ''

Python 3.10 support

I only get this errors when i try to run dvb.route() with python 3.10.6

ImportError: cannot import name 'Mapping' from 'collections' (/usr/lib/python3.10/collections/__init__.py)

Can someone migrate this project to 3.10+?

Migrate to WebAPI (fix routing)

Since EFA is going to be shut down at some point in the rather near future, it seems like a good idea to use the chance to migrate to use the WebAPI instead and also replace the widgets endpoint while at it.

Big upside is a whole bunch of new data being supplied by the WebAPI.

Failed to access VVO StopFinder

Something seems to be changed on the server side. :(

>>> import dvb
>>> dvb.find('zellesch')
Failed to access VVO StopFinder. Request Exception ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

RS

wo bleibt dvb-rs?

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.