Skip to content

juliuste/korail

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

47 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

korail

JavaScript client for the South Korean ๐Ÿ‡ฐ๐Ÿ‡ท korail railway API. Inofficial, using korail endpoints. Ask them for permission before using this module in production.

This module conforms to the FPTI-JS 0.3.2 standard for JavaScript public transportation modules.

npm version Build Status license fpti-js version chat on gitter

Installation

npm install korail

Usage

const korail = require('korail')

The korail module conforms to the FPTI-JS 0.3.2 standard for JavaScript public transportation modules and exposes the following methods:

Method Feature description FPTI-JS 0.3.2
stations.all([opt]) All stations of the Korail network, such as ์„œ์šธ, ๋ถ€์‚ฐ or ๋ชฉํฌ โœ… yes
journeys(origin, destination, [opt]) Journeys between stations โœ… yes
tripStopovers(tripId) All stopovers for a trip (all stations a given train passes) โŒ no

stations.all([opt])

Get all stations of the Korail network, such as ์„œ์šธ, ๋ถ€์‚ฐ or ๋ชฉํฌ. See this method in the FPTI-JS 0.3.2 spec.

Supported Options

There currently aren't any supported options for this method, but this might change in a future release.

Example

const korail = require('korail')
const stationStream = korail.stations.all()

stationStream.on('data', item => {
    // item is an FPTF station object
    console.log(item)
})
{
    type: "station",
    id: "0001",
    name: "์„œ์šธ",
    location: {
        type: "location",
        longitude: 126.9708191,
        latitude: 37.551856
    },
    group: "7",
    major: "1"
}

journeys(origin, destination, [opt])

Find journeys between stations. See this method in the FPTI-JS 0.3.2 spec.

Supported Options

Attribute Description FPTI-spec Value type Default
when Journey date, synonym to departureAfter โœ… Date new Date()
departureAfter List journeys with a departure (first leg) after this date โœ… Date new Date()
results Max. number of results returned โœ… Number null
interval Results for how many minutes after when/departureAfter โœ… Number null
transfers Max. number of transfers โœ… Number null
product Filter journey for specific train type โŒ Enum (String) KTX, ์ƒˆ๋งˆ์„, ๋ฌด๊ถํ™” (includes ๋ˆ„๋ฆฌ๋กœ), ์ฒญ์ถ˜

Please note that this module fetches a list of stations using the stations.all() method upon initialization, which takes about 3-4 seconds.

Example

const seoul = '0001' // station id
const busan = { // FPTF station
	type: 'station',
	id: '0020'
	// โ€ฆ
}
korail.journeys(seoul, busan, { when: new Date('2019-06-27T05:00:00+0200'), product: 'KTX', transfers: 0 }).then(โ€ฆ)
{
    type: "journey",
    id: "0001-2019-06-27t12-00-00-000-09-00-0020-2019-06-27t14-42-00-000-09-00-ktx-127",
    legs: [
        {
            origin: {
                type: "station",
                id: "0001",
                name: "์„œ์šธ",
                location: {
                    type: "location",
                    longitude: 126.9708191,
                    latitude: 37.551856
                },
                group: "7",
                major: "1"
            },
            destination: {
                type: "station",
                id: "0020",
                name: "๋ถ€์‚ฐ",
                location: {
                    type: "location",
                    longitude: 129.0415717,
                    latitude: 35.1150906
                },
                group: "6",
                major: "21"
            },
            departure: "2019-06-27T12:00:00.000+09:00",
            arrival: "2019-06-27T14:42:00.000+09:00",
            mode: "train",
            public: true,
            operator: {
                type: "operator",
                id: "korail",
                name: "korail",
                url: "https://www.letskorail.com"
            },
            line: {
                type: "line",
                id: "127",
                name: "KTX 127",
                product: {
                    id: "100",
                    name: "KTX"
                },
                mode: "train",
                operator: {
                    type: "operator",
                    id: "korail",
                    name: "korail",
                    url: "https://www.letskorail.com"
                }
            },
            tripId: "127###20190627"
        }
    ],
    price: {
        amount: 59800,
        currency: "KRW"
    }
}

tripStopovers(tripId)

All stopovers for a given trip (all stations a given train passes). Obtain a tripId using the journeys(origin, destination, [opt]) method. Returns a Promise that resolves in a list of stopovers.

Example

const tripId = '127###20190627' // taken from the journeys example above
korail.tripStopovers(tripId).then(โ€ฆ)
[
    {
        type: "stopover",
        stop: {
            type: "station",
            id: "0001",
            name: "์„œ์šธ"
        },
        arrival: null,
        departure: "2019-06-27T12:00:00.000+09:00"
    },
    {
        type: "stopover",
        stop: {
            type: "station",
            id: "0501",
            name: "๊ด‘๋ช…"
        },
        arrival: "2019-06-27T12:15:00.000+09:00",
        departure: "2019-06-27T12:16:00.000+09:00"
    },
    {
        type: "stopover",
        stop: {
            type: "station",
            id: "0502",
            name: "์ฒœ์•ˆ์•„์‚ฐ"
        },
        arrival: "2019-06-27T12:37:00.000+09:00",
        departure: "2019-06-27T12:39:00.000+09:00"
    },
    // โ€ฆ
    {
        type: "stopover",
        stop: {
            type: "station",
            id: "0020",
            name: "๋ถ€์‚ฐ"
        },
        arrival: "2019-06-27T14:42:00.000+09:00",
        departure: null
    }
]

Contributing

If you found a bug or want to propose a feature, feel free to visit the issues page.

About

Client for the South Korean korail railway API.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published