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
or clone this GitHub repository, if you want to expand upon it.
Usage
StopPlace
object
Create a StopPlace
object by handing in the NSR ID and a header (formatted like in the example below) to the constructor.
from pythentur import StopPlace
oslo_s = StopPlace("NSR:StopPlace:59872", "company - application")
This stores the ID, the name of the stop place (if available) and the header, for later use.
The number of calls to retrieve can be changed by changing the keyword argument noDepartures
in the get
method. The default is 20.
Journey
object
Create a Journey
object by handing in the NSR ID of a starting place and a destination (for now, these must be stop places, thus the NSR ID). In addition, a header is required (formatted like in the example below).
from pythentur import Journey
oslo_s_to_majorstuen = Journey("NSR:StopPlace:59872", "NSR:StopPlace:58381", "company - application")
This stores the from and to places, along with the header and the optional keyword arguments time
and noDepartures
.
time
defaults to the current time, but a custom time is supported. The time must be a datetime object.
noDepartures
is the number of journey alternatives to fetch. It defaults to 20.
get
method
This method is supported by both the StopPlace
object and the Journey
object. It makes a request to the Entur GraphQL API, by populating the query template with the NSR ID and the number of departures to get.
StopPlace.get()
from pythentur import StopPlace
oslo_s = StopPlace("NSR:StopPlace:59872", "company - application")
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.'readableTime'
: Returns a human readable string with relative time from now to the expected departure.
Journey.get()
from pythentur import Journey
oslo_s_to_majorstuen = Journey("NSR:StopPlace:59872", "NSR:StopPlace:58381", "company - application")
data = oslo_s_to_majorstuen.get()
Here data
is a list of different journey alternatives. Each of these alternatives are a list of the legs this journey has. Every leg contains
'transportMode'
: String describing the mode of transport for this leg.'aimedStartTime'
: Datetime object of the aimed start time of this leg.'expectedStartTime'
: Datetime object of the expected start time of this leg.'fromName'
: Name of the stop place the leg starts at.'fromId'
: NSR ID of the stop place the leg starts at.'toName'
: Name of the stop place the leg ends at.'toId'
: NSR ID of the stop place the leg ends at.'lineName'
: Display name of the arriving transport (not available iftransportMode
isfoot
).'lineNumber'
: Route number of the arriving transport (not available iftransportMode
isfoot
).'lineColor'
: Hex color value of the arriving transport (not available iftransportMode
isfoot
).
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pythentur-0.1.1.tar.gz
.
File metadata
- Download URL: pythentur-0.1.1.tar.gz
- Upload date:
- Size: 6.4 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9482da4b858e3992bc2d5f666feb7527bf23806f90730b1d1c1425530a5ded9c |
|
MD5 | d6318e944713dced710318ee1e64b6f7 |
|
BLAKE2b-256 | 0c734d99518fac2be554fa5063cb0646188eae13a0b6dd7a8825627ae1b536a7 |
File details
Details for the file pythentur-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: pythentur-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.4 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52438523dce7d03ec8b1ef465a3d90daf0cd4813e0f10607f4863bab562945d1 |
|
MD5 | df43cd0dc77d5f40b25f73c25baf2064 |
|
BLAKE2b-256 | d06b87636456244d4e9725b504410d0d77a86510698ab4f9b5a2afa8a687bd1b |