Skip to main content

Simplified data retrieval from Entur in Python

Project description

Pythentur

This package provides functions for simple fetching of real-time public transport data - as provided by Entur. As an added bonus, the nsrGet-function makes it easy to obtain the NSR ID of a stop place by a search string.

Installation

pip install pythentur

Dependencies:

Due to an issue, I'm not able to generate package dependencies, so they will have to be installed manually for the time being.

  • Requests

Usage

StopPlace object

Create a StopPlace object by handing in the NSR ID to the constructor.

from pythentur import StopPlace
oslo_s = StopPlace("NSR:StopPlace:59872")

This stores the ID and a pre-made query template in the GraphQL format.

Pythentur supports custom query templates, if you wish to retrieve more data. This is given to the constructor with the query argument.

query_template = "<graphQL query>"
oslo_s = StopPlace("NSR:StopPlace:59872", query = query_template)

This template string must have two spots (for the NSR ID and the number of calls to recieve) that are formattable by the Python format method. The GraphQL interface can be experimented with here.

StopPlace.get method

This method makes a request to the Entur GraphQL API, by populating the query template with the NSR ID and the number of calls to get. This retrieves a list of calls, each represented by a dictionary.

from pythentur import StopPlace
oslo_s = StopPlace("NSR:StopPlace:59872")
data = oslo_s.get()

Here, data is a list of dictionaries, each containing:

  • 'platform': String containing the platform this call is arriving on. May be a blank string if the stop place does not have different specified platforms.
  • 'line': String containing the line number and name of the arriving transport.
  • 'aimedArrivalTime': Datetime object containing the planned arrival time of the call.
  • 'expectedArrivalTime': Datetime object containing the expected arrival time of the call.
  • 'delay': Timedelta object containing the calculated delay of the call.

The number of calls to retrieve can be changed by changing the argument noDepartures in the get method. The default is 20.

In addition to getting the departure data for the stop, get also fetches the name of the stop and stores it in a variable name.

StopPlace.getCustom method

Given a custom query, the get method will (probably) not work. In this case, the getCustom method should be used, and will return the resulting json data back as a dictionary.

nsrGet function

Utilizing nsrGet, finding NSR IDs becomes a breeze. Hand in a search string to the function, and it spits out a list of IDs from stop places matching that string.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pythentur-0.0.4.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

pythentur-0.0.4-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file pythentur-0.0.4.tar.gz.

File metadata

  • Download URL: pythentur-0.0.4.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1

File hashes

Hashes for pythentur-0.0.4.tar.gz
Algorithm Hash digest
SHA256 75ec4e997802cedebc424a1df508e29a173dca5209f1114b598d09bea9d22b87
MD5 067b46e16bf1169a1873a5e6b0270b6a
BLAKE2b-256 1d2c384d31853f2e0b7341f981466bc224a2ae23996cf75d38b565b036e6f8c5

See more details on using hashes here.

File details

Details for the file pythentur-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: pythentur-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1

File hashes

Hashes for pythentur-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 814a9fdc667f54e4e90dbec8b7831f2d2147fc8aa0b9aee549c5148356f9855d
MD5 cbd97158356562ab30fa4131d727b9b6
BLAKE2b-256 003ec829d8e818f44850ee0af78fe8a1d8a9567b774513c798b785db3a3a0977

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page