metlink-python


Namemetlink-python JSON
Version 0.1.0 PyPI version JSON
download
home_page
SummaryAPI Wrapper and CLI for Metlink API
upload_time2023-03-14 03:36:29
maintainer
docs_urlNone
authorHarry Ludemann
requires_python
license
keywords python metlink api wrapper cli
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Metlink-Python

[![](https://github.com/HarryLudemann/Metlink-Python/workflows/pytests/badge.svg)]()

[![Maintainability](https://api.codeclimate.com/v1/badges/08e4dc1f109aaa6c4f75/maintainability)](https://codeclimate.com/github/HarryLudemann/Metlink-Python/maintainability)

   

Python wrapper and CLI for the [Wellington Metlink's](https://gwrc-opendata.auth.ap-southeast-2.amazoncognito.com/signup?response_type=token&client_id=4bmn2icphpqls57ijr7k4okv55&redirect_uri=https://opendata.metlink.org.nz/index.html?action=login) API and static data, this requires a free api key from [Metlink](https://gwrc-opendata.auth.ap-southeast-2.amazoncognito.com/signup?response_type=token&client_id=4bmn2icphpqls57ijr7k4okv55&redirect_uri=https://opendata.metlink.org.nz/index.html?action=login).



### Install Module:

```

pip install metlink-python

```

or

```

pip3 install metlink-python

```

### Get API KEY

1. Register at [Metlink](https://gwrc-opendata.auth.ap-southeast-2.amazoncognito.com/signup?response_type=token&client_id=4bmn2icphpqls57ijr7k4okv55&redirect_uri=https://opendata.metlink.org.nz/index.html?action=login)

2. Login

3. Get API key from [My Dashboard](https://opendata.metlink.org.nz/dashboard)



### CLI

#### Setup:

Create python file containing the following code with your API key, for example called 'main.py' containing:

```python

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.

```python

pip install rich

```

or

```python

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.

```python

from metlink import Metlink



metlink = Metlink('FakeAPIKEYaiofuhaeaubaaoanaiscai')

```

#### Vehicle Positions Example:

```python

vehicle_positions = metlink.get_vehicle_positions()

for position in vehicle_positions:

    print( position.get('bearing'), position.get('latitude'), position.get('longitude') )

```

#### Trip Updates Example:

```python

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:

```python

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:

```python

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






            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "metlink-python",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "python,metlink,api,wrapper,cli",
    "author": "Harry Ludemann",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/01/75/7599d03e65c306da8b427fb20c1a8d92da07074431bb59b849ed568fb3eb/metlink-python-0.1.0.tar.gz",
    "platform": null,
    "description": "\n# Metlink-Python\n\n[![](https://github.com/HarryLudemann/Metlink-Python/workflows/pytests/badge.svg)]()\n\n[![Maintainability](https://api.codeclimate.com/v1/badges/08e4dc1f109aaa6c4f75/maintainability)](https://codeclimate.com/github/HarryLudemann/Metlink-Python/maintainability)\n\n   \n\nPython wrapper and CLI for the [Wellington Metlink's](https://gwrc-opendata.auth.ap-southeast-2.amazoncognito.com/signup?response_type=token&client_id=4bmn2icphpqls57ijr7k4okv55&redirect_uri=https://opendata.metlink.org.nz/index.html?action=login) API and static data, this requires a free api key from [Metlink](https://gwrc-opendata.auth.ap-southeast-2.amazoncognito.com/signup?response_type=token&client_id=4bmn2icphpqls57ijr7k4okv55&redirect_uri=https://opendata.metlink.org.nz/index.html?action=login).\n\n\n\n### Install Module:\n\n```\n\npip install metlink-python\n\n```\n\nor\n\n```\n\npip3 install metlink-python\n\n```\n\n### Get API KEY\n\n1. Register at [Metlink](https://gwrc-opendata.auth.ap-southeast-2.amazoncognito.com/signup?response_type=token&client_id=4bmn2icphpqls57ijr7k4okv55&redirect_uri=https://opendata.metlink.org.nz/index.html?action=login)\n\n2. Login\n\n3. Get API key from [My Dashboard](https://opendata.metlink.org.nz/dashboard)\n\n\n\n### CLI\n\n#### Setup:\n\nCreate python file containing the following code with your API key, for example called 'main.py' containing:\n\n```python\n\nfrom metlink import CLI\n\n\n\nCLI('api_key')\n\n```\n\n#### Test:\n\nThen run the created script with the argument '-h' to display all arguments.\n\n```\n\npython main.py -h\n\n```\n\nor \n\n```\n\npython3 main.py -h\n\n```\n\nReturning:\n\n```\n\nArguments:\n\n    -h, --help                show this help message\n\n    -v, --version             show program's version number\n\n\n\n    Style Table:\n\n        --lines               Show lines between rows\n\n        --rich                Use rich module to style table\n\n\n\n    API Filters:\n\n        --stop STOP      Select Stop\n\n        --route ROUTE   Select Route\n\n        --trip TRIP      Select Trip\n\n\n\n    API Information to display:\n\n        --stops                   Prints stop information,\n\n                                    filters: --trip, --route\n\n        --routes                  Prints route information,\n\n                                    filters: --stop\n\n        --vehicle_positions       Prints vehicle positions,\n\n                                    filters: N/A\n\n        --trip_updates            Prints trip updates,\n\n                                    filters: N/A\n\n        --service_alerts          Prints service alerts,\n\n                                    filters: N/A\n\n        --stop_predictions        Prints stop predictions,\n\n                                    filters: --stop\n\n```\n\n\n\n#### Examples:\n\nFor example run this command to get a table of service alerts, note this example requires the rich module (remove --rich to use without).\n\n```\n\npython main.py [options]\n\npython metlink.py --help\n\npython metlink.py --trip_updates\n\npython metlink.py --trip_updates --rich\n\npython metlink.py --stop 5000 --routes --rich\n\n```\n\n#### Optionally Install Rich Module\n\nOptionally you can install the rich module to visually make the returned tables more attractive.\n\n```python\n\npip install rich\n\n```\n\nor\n\n```python\n\npip3 install rich\n\n```\n\n\n\n### Python Module\n\n#### Initialize Module:\n\nTo use any of the functions you need to initialize the class at the start of the script.\n\n```python\n\nfrom metlink import Metlink\n\n\n\nmetlink = Metlink('FakeAPIKEYaiofuhaeaubaaoanaiscai')\n\n```\n\n#### Vehicle Positions Example:\n\n```python\n\nvehicle_positions = metlink.get_vehicle_positions()\n\nfor position in vehicle_positions:\n\n    print( position.get('bearing'), position.get('latitude'), position.get('longitude') )\n\n```\n\n#### Trip Updates Example:\n\n```python\n\ntrip_updates = metlink.get_trip_updates()\n\n\n\nfor update in trip_updates:\n\n    print( update.get('stop_id'), update.get('arrival_delay'), update.get('arrival_time') )\n\n```\n\n#### Service Alerts Example:\n\n```python\n\nservice_alerts = metlink.get_service_alerts()\n\nfor index, alert in enumerate(service_alerts):\n\n    print('Alert', index )\n\n    if alert.get('header_text') is not None:\n\n        print( alert.get('header_text') )\n\n    print( 'effect:', alert.get('effect') )\n\n    print( 'cause', alert.get('cause'), '\\n' )\n\n```\n\n\n\n#### Stop Predictions Example:\n\n```python\n\nstop_predictions = metlink.get_stop_predictions(stop_id=7912)\n\n\n\nfor pred in stop_predictions:\n\n    if pred.get('status') is not None:\n\n        print(pred.get('service_id'), pred.get('status'))\n\n```\n\n\n\n#### Module Functions:\n\n* **get_stop_predictions(stop_id=None)**      \n\n    Passed stop_id, returns list of dictionary's   \n\n    **Param**: stop_id   \n\n    * service_id\n\n    * name\n\n    * vehicle_id\n\n    * direction\n\n    * status\n\n    * trip_id\n\n    * delay\n\n    * monitored\n\n    * operator\n\n    * origin\n\n    * wheelchair_accessible\n\n    * departure\n\n    * arrival\n\n\n\n* **get_service_alerts()**   \n\n    Trip Updates - Information about unforeseen events affecting routes, stops, or the network. Given nothing, returns list of dictionaries.   \n\n    **Param**: N/A   \n\n    * active_period\n\n    * effect\n\n    * cause\n\n    * description_text\n\n    * header_text\n\n    * severity_level\n\n    * informed_entity\n\n\n\n* **get_vehicle_positions()**   \n\n    Vehicle Positions - API to get Information about vehicles including location. Given nothing, returns list of dictionaries. if no busses are active returns empty list   \n\n    **Param**: N/A   \n\n    * vehicle_id\n\n    * bearing\n\n    * latitude\n\n    * longitude\n\n\n\n* **get_trip_updates()**   \n\n    Trip Updates - Delays, cancellations, changed routes. Given nothing, returns list of dictionaries. returns empty list if no trip delays or changes   \n\n    **Param**: N/A   \n\n    * stop_id\n\n    * arrival_delay\n\n    * arrival_time\n\n    * trip_start_time\n\n    * vehicle_id\n\n\n\n* **get_routes(stop_id=None)**   \n\n    Returns list of dictionarys of route infomation, optionally given stop_id as filter   \n\n    **Param**: Optional stop_id   \n\n    * id\n\n    * route_id\n\n    * agency_id\n\n    * route_short_name\n\n    * route_long_name\n\n    * route_desc\n\n    * route_type\n\n    * route_color\n\n    * route_text_color\n\n    * route_url\n\n\n\n* **get_stops(trip_id=None, route_id=None)**   \n\n    Returns list of dictionarys of stops infomation, optionally given trip_id and or route_id   \n\n    **Param**: Optional trip_id and or route_id\n\n    * id\n\n    * stop_id\n\n    * stop_code\n\n    * stop_name\n\n    * stop_desc\n\n    * zone_id\n\n    * stop_lat\n\n    * stop_lon\n\n    * location_type\n\n    * parent_station\n\n    * stop_url\n\n    * stop_timezone\n\n\n\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "API Wrapper and CLI for Metlink API",
    "version": "0.1.0",
    "split_keywords": [
        "python",
        "metlink",
        "api",
        "wrapper",
        "cli"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e16ec6ecf1cb300ec77eedc9b1636c5e3a6b5a899e45f3e1625bdbb9eff06f50",
                "md5": "1172d2af08760990636f3d213448549a",
                "sha256": "cc508e96be74a27c68250ac00bee608e435d3d09ee0655b528a80d11fb5cf442"
            },
            "downloads": -1,
            "filename": "metlink_python-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1172d2af08760990636f3d213448549a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 8964,
            "upload_time": "2023-03-14T03:36:27",
            "upload_time_iso_8601": "2023-03-14T03:36:27.625283Z",
            "url": "https://files.pythonhosted.org/packages/e1/6e/c6ecf1cb300ec77eedc9b1636c5e3a6b5a899e45f3e1625bdbb9eff06f50/metlink_python-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "01757599d03e65c306da8b427fb20c1a8d92da07074431bb59b849ed568fb3eb",
                "md5": "2e976c8770ad058ba08c92550a9f3bb1",
                "sha256": "7c77a52d074c8e56c8ffdb5b59aeda86aa82944fac6cef3837d5cc0286ccf474"
            },
            "downloads": -1,
            "filename": "metlink-python-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "2e976c8770ad058ba08c92550a9f3bb1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 9954,
            "upload_time": "2023-03-14T03:36:29",
            "upload_time_iso_8601": "2023-03-14T03:36:29.805381Z",
            "url": "https://files.pythonhosted.org/packages/01/75/7599d03e65c306da8b427fb20c1a8d92da07074431bb59b849ed568fb3eb/metlink-python-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-14 03:36:29",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "metlink-python"
}
        
Elapsed time: 0.06464s