Package: metlink-python
Metlink-PythonPython wrapper and CLI for theWellington Metlink'sAPI and static data, this requires a free api key fromMetlink.Install Module:pip install metlink-pythonorpip3 install metlink-pythonGet API KEYRegister atMetlinkLoginGet API key fromMy DashboardCLISetup:Create python file containing the following code with your API key, for example called 'main.py' containing:frommetlinkimportCLICLI('api_key')Test:Then run the created script with the argument '-h' to display all arguments.python main.py -horpython3 main.py -hReturning: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: --stopExamples: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 --richOptionally Install Rich ModuleOptionally you can install the rich module to visually make the returned tables more attractive.pipinstallrichorpip3installrichPython ModuleInitialize Module:To use any of the functions you need to initialize the class at the start of the script.frommetlinkimportMetlinkmetlink=Metlink('FakeAPIKEYaiofuhaeaubaaoanaiscai')Vehicle Positions Example:vehicle_positions=metlink.get_vehicle_positions()forpositioninvehicle_positions:print(position.get('bearing'),position.get('latitude'),position.get('longitude'))Trip Updates Example:trip_updates=metlink.get_trip_updates()forupdateintrip_updates:print(update.get('stop_id'),update.get('arrival_delay'),update.get('arrival_time'))Service Alerts Example:service_alerts=metlink.get_service_alerts()forindex,alertinenumerate(service_alerts):print('Alert',index)ifalert.get('header_text')isnotNone: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)forpredinstop_predictions:ifpred.get('status')isnotNone:print(pred.get('service_id'),pred.get('status'))Module Functions:get_stop_predictions(stop_id=None)Passed stop_id, returns list of dictionary'sParam: stop_idservice_idnamevehicle_iddirectionstatustrip_iddelaymonitoredoperatororiginwheelchair_accessibledeparturearrivalget_service_alerts()Trip Updates - Information about unforeseen events affecting routes, stops, or the network. Given nothing, returns list of dictionaries.Param: N/Aactive_periodeffectcausedescription_textheader_textseverity_levelinformed_entityget_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 listParam: N/Avehicle_idbearinglatitudelongitudeget_trip_updates()Trip Updates - Delays, cancellations, changed routes. Given nothing, returns list of dictionaries. returns empty list if no trip delays or changesParam: N/Astop_idarrival_delayarrival_timetrip_start_timevehicle_idget_routes(stop_id=None)Returns list of dictionarys of route infomation, optionally given stop_id as filterParam: Optional stop_ididroute_idagency_idroute_short_nameroute_long_nameroute_descroute_typeroute_colorroute_text_colorroute_urlget_stops(trip_id=None, route_id=None)Returns list of dictionarys of stops infomation, optionally given trip_id and or route_idParam: Optional trip_id and or route_ididstop_idstop_codestop_namestop_desczone_idstop_latstop_lonlocation_typeparent_stationstop_urlstop_timezone