API Wrapper and CLI for Metlink API
Project description
Metlink-Python
Python wrapper and CLI for the Wellington Metlink's API and static data, this requires a free api key from Metlink.
Install Module:
pip install metlink-python
or
pip3 install metlink-python
Get API KEY
-
Register at Metlink
-
Login
-
Get API key from My Dashboard
CLI
Setup:
Create python file containing the following code with your API key, for example called 'main.py' containing:
from metlink import CLI
CLI('api_key')
Test:
Then run the created script with the argument '-h' to display all arguments.
python main.py -h
or
python3 main.py -h
Returning:
Arguments:
-h, --help show this help message
-v, --version show program's version number
Style Table:
--lines Show lines between rows
--rich Use rich module to style table
API Filters:
--stop STOP Select Stop
--route ROUTE Select Route
--trip TRIP Select Trip
API Information to display:
--stops Prints stop information,
filters: --trip, --route
--routes Prints route information,
filters: --stop
--vehicle_positions Prints vehicle positions,
filters: N/A
--trip_updates Prints trip updates,
filters: N/A
--service_alerts Prints service alerts,
filters: N/A
--stop_predictions Prints stop predictions,
filters: --stop
Examples:
For example run this command to get a table of service alerts, note this example requires the rich module (remove --rich to use without).
python main.py [options]
python metlink.py --help
python metlink.py --trip_updates
python metlink.py --trip_updates --rich
python metlink.py --stop 5000 --routes --rich
Optionally Install Rich Module
Optionally you can install the rich module to visually make the returned tables more attractive.
pip install rich
or
pip3 install rich
Python Module
Initialize Module:
To use any of the functions you need to initialize the class at the start of the script.
from metlink import Metlink
metlink = Metlink('FakeAPIKEYaiofuhaeaubaaoanaiscai')
Vehicle Positions Example:
vehicle_positions = metlink.get_vehicle_positions()
for position in vehicle_positions:
print( position.get('bearing'), position.get('latitude'), position.get('longitude') )
Trip Updates Example:
trip_updates = metlink.get_trip_updates()
for update in trip_updates:
print( update.get('stop_id'), update.get('arrival_delay'), update.get('arrival_time') )
Service Alerts Example:
service_alerts = metlink.get_service_alerts()
for index, alert in enumerate(service_alerts):
print('Alert', index )
if alert.get('header_text') is not None:
print( alert.get('header_text') )
print( 'effect:', alert.get('effect') )
print( 'cause', alert.get('cause'), '\n' )
Stop Predictions Example:
stop_predictions = metlink.get_stop_predictions(stop_id=7912)
for pred in stop_predictions:
if pred.get('status') is not None:
print(pred.get('service_id'), pred.get('status'))
Module Functions:
-
get_stop_predictions(stop_id=None)
Passed stop_id, returns list of dictionary's
Param: stop_id
-
service_id
-
name
-
vehicle_id
-
direction
-
status
-
trip_id
-
delay
-
monitored
-
operator
-
origin
-
wheelchair_accessible
-
departure
-
arrival
-
-
get_service_alerts()
Trip Updates - Information about unforeseen events affecting routes, stops, or the network. Given nothing, returns list of dictionaries.
Param: N/A
-
active_period
-
effect
-
cause
-
description_text
-
header_text
-
severity_level
-
informed_entity
-
-
get_vehicle_positions()
Vehicle Positions - API to get Information about vehicles including location. Given nothing, returns list of dictionaries. if no busses are active returns empty list
Param: N/A
-
vehicle_id
-
bearing
-
latitude
-
longitude
-
-
get_trip_updates()
Trip Updates - Delays, cancellations, changed routes. Given nothing, returns list of dictionaries. returns empty list if no trip delays or changes
Param: N/A
-
stop_id
-
arrival_delay
-
arrival_time
-
trip_start_time
-
vehicle_id
-
-
get_routes(stop_id=None)
Returns list of dictionarys of route infomation, optionally given stop_id as filter
Param: Optional stop_id
-
id
-
route_id
-
agency_id
-
route_short_name
-
route_long_name
-
route_desc
-
route_type
-
route_color
-
route_text_color
-
route_url
-
-
get_stops(trip_id=None, route_id=None)
Returns list of dictionarys of stops infomation, optionally given trip_id and or route_id
Param: Optional trip_id and or route_id
-
id
-
stop_id
-
stop_code
-
stop_name
-
stop_desc
-
zone_id
-
stop_lat
-
stop_lon
-
location_type
-
parent_station
-
stop_url
-
stop_timezone
-
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 metlink-python-0.1.0.tar.gz
.
File metadata
- Download URL: metlink-python-0.1.0.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c77a52d074c8e56c8ffdb5b59aeda86aa82944fac6cef3837d5cc0286ccf474 |
|
MD5 | 2e976c8770ad058ba08c92550a9f3bb1 |
|
BLAKE2b-256 | 01757599d03e65c306da8b427fb20c1a8d92da07074431bb59b849ed568fb3eb |
File details
Details for the file metlink_python-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: metlink_python-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc508e96be74a27c68250ac00bee608e435d3d09ee0655b528a80d11fb5cf442 |
|
MD5 | 1172d2af08760990636f3d213448549a |
|
BLAKE2b-256 | e16ec6ecf1cb300ec77eedc9b1636c5e3a6b5a899e45f3e1625bdbb9eff06f50 |