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.0.tar.gz
.
File metadata
- Download URL: pythentur-0.1.0.tar.gz
- Upload date:
- Size: 6.5 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 | 845ee42562716edb1f07df99ea6528bba2d10482c0ec7e2909aabcf67fbfe68e |
|
MD5 | 063c3934805c5eeff17bf8db591b40ea |
|
BLAKE2b-256 | e66c82a96684048fb1b4781a9d96f443bcd6f3e30aff053de4c81a2d4a4a0d64 |
File details
Details for the file pythentur-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: pythentur-0.1.0-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 | 3c0beea8552b2444011ba9f8e0ae5c396e22bef8dd08ef61fa2535870a317eba |
|
MD5 | 2c554c77edff65633e3bc6fe31f30bac |
|
BLAKE2b-256 | 59389937d3f109c1cd7f508a94d4129d92e9677edc4bf0612add077a07feda8f |