Git Product home page Git Product logo

public-transport-ireland's Introduction

public-transport-ireland

Node.js module with utility functions to get real time data for Irish public transport (Irish Rail, Luas, Dublin Bus)

npm version Monthly Downloads Build Status JavaScript Style Guide

Install

With NPM:

npm install --save public-transport-ireland

Requires Node.js v8+

Sample usage

This module contains several sub modules. You can globally import all submodules by doing something like this:

const publicTransport = require('public-transport-ireland')

// access dublinBus.getStops
console.log(publicTransport.dublinBus.getStops) // function

However, since every sub module might allocate resources (e.g. SOAP or HTTP clients) as soon as they are imported, it is recommended to directly import the sub modules that you want to use:

const dublinBus = require('public-transport-ireland/dublin-bus')

// access dublinBus.getStops
console.log(dublinBus.getStops) // function

Sub modules available

  • dublin-bus: require('public-transport-ireland/dublin-bus')
  • irish-rail: require('public-transport-ireland/irish-rail')
  • luas: require('public-transport-ireland/luas')

๐ŸšŒ Dublin Bus

Allows to get all the stops and the real time information for a stop.

Exported items

  • getStops(): get information about all available stops
  • getRealTimeInfo(stopId: number): get real time information for a given bus stop

Examples

Get all the stops and then the real time information for the first stop:

'use strict'

const { getStops, getRealTimeInfo } = require('public-transport-ireland/dublin-bus')

async function main () {
  const allStops = await getStops()
  console.log('allStops', allStops)
  const realTimeDataForFirstStop = await getRealTimeInfo(allStops[0].code)
  console.log('realTimeDataForFirstStop', realTimeDataForFirstStop)
}

main()

This will print:

allStops [
  {
    id: 2,
    code: "2",
    longitude: -6.263695,
    latitude: 53.352241,
    description: 'Parnell Square, Parnell Street'
  },
  {
    id: 3,
    code: "3",
    longitude: -6.263783,
    latitude: 53.352307,
    description: 'Parnell Square, Granby Place'
  },
  // ...
]

realTimeDataForFirstStop [
  {
    lineName: '46A',
    destinationName: 'Phoenix Pk via Donnybrook',
    destination: '46A - Phoenix Pk via Donnybrook',
    expectedArrivalTime: '2019-09-22T16:59:59.000+01:00',
    vehicleAtStop: false,
    arrivingInMinutes: 5
  },
  {
    lineName: '38',
    destinationName: 'Damastown via Corduff',
    destination: '38 - Damastown via Corduff',
    expectedArrivalTime: '2019-09-22T17:04:05.000+01:00',
    vehicleAtStop: false,
    arrivingInMinutes: 9
  },
  // ...
]

๐Ÿš‚ Irish Rail

Allows to get all the stations and the real time information for a station.

Exported items

  • getStations(): get information about all available train stations
  • getRealTimeInfo(stationCode: string, direction?: Direction): Get information about trains arriving at a given station
  • Direction: an object that contains all the well known directions (key/value pairs)

Examples

Get all the available stations and then the real time information for the first station:

'use strict'

const { getStations, getRealTimeInfo } = require('public-transport-ireland/irish-rail')

async function main () {
  const allStations = await getStations()
  console.log('allStations', allStations)
  const realTimeDataForFirstStation = await getRealTimeInfo(allStations[0].code)
  console.log('realTimeDataForFirstStation', realTimeDataForFirstStation)
}

main()

This will print:

allStations [
  {
    id: 228,
    code: 'BFSTC',
    name: 'Belfast',
    longitude: -5.91744,
    latitude: 54.6123
  },
  {
    id: 238,
    code: 'LBURN',
    name: 'Lisburn',
    longitude: -6.04327,
    latitude: 54.514
  },
  // ...
]
realTimeDataForFirstStation [
  {
    code: 'A122',
    origin: 'Dublin Connolly',
    destination: 'Belfast',
    originTime: '2019-09-23T07:35:00.000+01:00',
    destinationTime: '2019-09-23T09:45:00.000+01:00',
    status: 'En Route',
    arrivingInMinutes: 2,
    minutesLate: 5,
    expectedArrivalTime: '2019-09-23T09:50:00.000+01:00',
    expectedDepartureTime: '2019-09-23T00:00:00.000+01:00',
    scheduledArrivalTime: '2019-09-23T09:45:00.000+01:00',
    scheduledDepartureTime: '2019-09-23T00:00:00.000+01:00',
    direction: 'Northbound',
    trainType: 'Train'
  },
  {
    code: 'A125',
    origin: 'Belfast',
    destination: 'Dublin Connolly',
    originTime: '2019-09-23T10:35:00.000+01:00',
    destinationTime: '2019-09-23T12:40:00.000+01:00',
    status: 'No Information',
    arrivingInMinutes: 47,
    minutesLate: 0,
    expectedArrivalTime: '2019-09-23T00:00:00.000+01:00',
    expectedDepartureTime: '2019-09-23T10:35:00.000+01:00',
    scheduledArrivalTime: '2019-09-23T00:00:00.000+01:00',
    scheduledDepartureTime: '2019-09-23T10:35:00.000+01:00',
    direction: 'Southbound',
    trainType: 'Train'
  },
  // ...
]

When getting real time information you can also pass an additional parameter to filter on a specific "direction" (e.g. "Southbound" or "Northbound") as in the following example:

'use strict'

const { getRealTimeInfo, Direction } = require('public-transport-ireland/irish-rail')

async function main () {
  const realTimeDataForAshtownSouthbound = await getRealTimeInfo('ASHTN', Direction.SOUTHBOUND)
  console.log('realTimeDataForAshtownSouthbound', realTimeDataForAshtownSouthbound)
}

main()

This should print something like this:

realTimeDataForAshtownSouthbound [
  {
    code: 'P740',
    origin: 'Maynooth',
    destination: 'Dublin Connolly',
    originTime: '2019-09-23T10:40:00.000+01:00',
    destinationTime: '2019-09-23T11:22:00.000+01:00',
    status: 'En Route',
    arrivingInMinutes: 1,
    minutesLate: 9,
    expectedArrivalTime: '2019-09-23T11:17:00.000+01:00',
    expectedDepartureTime: '2019-09-23T11:17:00.000+01:00',
    scheduledArrivalTime: '2019-09-23T11:07:00.000+01:00',
    scheduledDepartureTime: '2019-09-23T11:08:00.000+01:00',
    direction: 'Southbound',
    trainType: 'Train'
  },
  {
    code: 'P742',
    origin: 'Maynooth',
    destination: 'Dublin Connolly',
    originTime: '2019-09-23T11:40:00.000+01:00',
    destinationTime: '2019-09-23T12:22:00.000+01:00',
    status: 'No Information',
    arrivingInMinutes: 52,
    minutesLate: 0,
    expectedArrivalTime: '2019-09-23T12:07:00.000+01:00',
    expectedDepartureTime: '2019-09-23T12:08:00.000+01:00',
    scheduledArrivalTime: '2019-09-23T12:07:00.000+01:00',
    scheduledDepartureTime: '2019-09-23T12:08:00.000+01:00',
    direction: 'Southbound',
    trainType: 'Train'
  },
  // ...
]

Note that you can use the Direction object to get a list of well known directions.

๐Ÿšƒ Luas

Allows to get all the stops, stop status and the real time information for a stop.

Exported items

  • getStops(lineFilter?: Line): get all the available luas stop. Can filter by line
  • getRealTimeInfo(stopCode: string, directionFilter?: Direction): get realtime information for a given stop
  • getStopStatus(stopCode: string): get the status of a given stop
  • Line: an object that contains all the well known lines (key/value pairs)
  • Direction: an object that contains all the well known directions (key/value pairs)

Examples

Get all the available stops and then the real time information for the first stop:

'use strict'

const { getStops, getStopStatus, getRealTimeInfo } = require('public-transport-ireland/luas')

async function main () {
  const allStops = await getStops()
  console.log('allStops', allStops)

  const firstStopStatus = await getStopStatus(allStops[0].code)
  console.log('firstStopStatus', firstStopStatus)

  const firstStopRealTimeInfo = await getRealTimeInfo(allStops[0].code)
  console.log('firstStopRealTimeInfo', firstStopRealTimeInfo)
}

main()

This should print something like this:

allStops [
  {
    line: 'Luas Red Line',
    name: 'The Point',
    pronunciation: 'The Point',
    code: 'TPT',
    isParkRide: false,
    isCycleRide: false,
    latitude: 53.34835,
    longitude: -6.22925833333333,
    outboundStatusMessage: 'Services operating normally',
    outboundOperatingNormally: true,
    outboundForecastsEnabled: true,
    inboundStatusMessage: 'Services operating normally',
    inboundOperatingNormally: true,
    inboundForecastsEnabled: true
  },
  // ...
]
firstStopStatus [
  {
    direction: 'Inbound',
    statusMessage: 'Services operating normally',
    forecastsEnabled: true,
    operatingNormally: true
  },
  // ...
]
firstStopRealTimeInfo [
  {
    direction: 'Inbound',
    destination: 'No trams forecast',
    arrivingInMinutes: 0,
    expectedArrivalTime: '2019-09-23T20:01:46.000+01:00'
  },
  // ...
]

The getStops function accept an optional parameter to filter on the line. To get the stops only for the Red line you can do something like this:

'use strict'

const { Line, getStops } = require('public-transport-ireland/luas')

async function main () {
  const redLineStops = await getStops(Line.RED)
  console.log('redLineStops', redLineStops)
}

main()

This will print something like this:

redLineStops [
  {
    line: 'Luas Red Line',
    name: 'The Point',
    pronunciation: 'The Point',
    code: 'TPT',
    isParkRide: false,
    isCycleRide: false,
    latitude: 53.34835,
    longitude: -6.22925833333333,
    outboundStatusMessage: 'Services operating normally',
    outboundOperatingNormally: true,
    outboundForecastsEnabled: true,
    inboundStatusMessage: 'Services operating normally',
    inboundOperatingNormally: true,
    inboundForecastsEnabled: true
  },
  // ...
]

Note that you can use the Line object to get a list of well known lines.


The getRealTimeInfo function allows you to pass an optional parameter to filter on a given direction:

'use strict'

const { Direction, getRealTimeInfo } = require('public-transport-ireland/luas')

async function main () {
  const realTimeInboundInfoForDominic = await getRealTimeInfo('DOM', Direction.INBOUND)
  console.log('realTimeInboundInfoForDominic', realTimeInboundInfoForDominic)
}

main()

This will print something like this:

realTimeInboundInfoForDominic [
  {
    direction: 'Inbound',
    destination: 'Broombridge',
    arrivingInMinutes: 6,
    expectedArrivalTime: '2019-09-23T20:19:02.000+01:00'
  },
  {
    direction: 'Inbound',
    destination: 'Broombridge',
    arrivingInMinutes: 15,
    expectedArrivalTime: '2019-09-23T20:28:02.000+01:00'
  }
]

Note that you can use the Direction object to get a list of well known directions.

Contributing

Everyone is very welcome to contribute to this project. You can contribute just by submitting bugs or suggesting improvements by opening an issue on GitHub or PRs.

License

Licensed under MIT License. ยฉ Luciano Mammino.

public-transport-ireland's People

Contributors

ckotzbauer avatar lmammino avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.