/MTR-Next-Train

an API to retrieve MTR (Mass Transit Railway) train schedules for a specific line and station in Hong Kong.

Primary LanguageJavaScriptMIT LicenseMIT

MTR Schedule API

This is a Go application that provides an API to fetch MTR (Mass Transit Railway) train schedules for specific lines and stations in Hong Kong. The API retrieves real-time data from the Hong Kong Open Data platform.

Release Notes

The js version is the original project, maintained by Dr.Sark.

Demo

  1. Open your web browser and navigate to the following URL:
https://aoo.mx/mtr/TML/ETS

Replace EAL with the code of the desired MTR line (e.g., AEL for Airport Express) and HUH with the code of the desired MTR station (e.g., HUH for Hung Hom). The API will return a JSON response containing the train schedule for the specified line and station.

Usage

  1. Start the server by running the following command:

    ./mtr-api

    The server will start running on http://localhost:3200.

  2. Access the API using the following endpoint:

    GET /api/v1/:line/:station
    
    • Replace :line with the code of the desired MTR line (e.g., AEL for Airport Express).
    • Replace :station with the code of the desired MTR station (e.g., HOK for Hong Kong).

The API will return a JSON response containing the train schedule for the specified line and station.

API Response

{
    "line":"East Rail Line",
    "schedule":{
        "DOWN":[
            {
                "destination":"Admiralty",
                "arrival_time":"05:54",
                "time_diff":"154"
            },
            {
                "destination":"Admiralty",
                "arrival_time":"06:00",
                "time_diff":"160"
            },
            {
                "destination":"Admiralty",
                "arrival_time":"06:08",
                "time_diff":"168"
            },
            {
                "destination":"Admiralty",
                "arrival_time":"06:16",
                "time_diff":"176"
            }
        ],
        "UP":[
            {
                "destination":"Lo Wu",
                "arrival_time":"05:29",
                "time_diff":"129"
            },
            {
                "destination":"Lok Ma Chau",
                "arrival_time":"05:31",
                "time_diff":"131"
            },
            {
                "destination":"Lo Wu",
                "arrival_time":"05:36",
                "time_diff":"136"
            },
            {
                "destination":"Lo Wu",
                "arrival_time":"05:44",
                "time_diff":"144"
            }
        ]
    },
    "station":"Hung Hom"
}
  • line: The name of the MTR line.
  • station: The name of the MTR station.
  • schedule: An object containing train schedules for both the "UP" and "DOWN" directions.
  • UP: An array of strings representing upcoming train arrivals in the "UP" direction.
  • DOWN: An array of strings representing upcoming train arrivals in the "DOWN" direction.