Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including transperthapi with all npm packages installed. Try it out:

var transperthapi = require("transperthapi")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

transperthapi v1.0.3

An API written to scrape data from TransPerth services.

TransPerth API

Build Status Coverage Status

This is an API that allows read-only access to information from TransPerth such as the scheduled arrival time of trains, buses and ferries at stopping points as well as SmartRider data.

Documentation

Documentation for this project can be found at maxrumsey.xyz.

Example

These examples fetch data from a SmartRider as well as the expected arrival time of a bus.

SmartRider

const transperth = require('transperthapi');
const Client = new transperth();
Client.smartRiderInfo('SR 1234 5678 9') // Example SmartRider Number
  .then(data => {
    if (data.error) throw new Error(data.error);

    console.log(data);

    //  {
    //    balance: '$XX.XX',
    //    conc_type: '' || 'Concession Description',
    //    conc_expirt: 'XX/XX/XX',
    //    autolad: 'True | False'
    //    meta: { endpoint: 'http://...' }
    //  }
  })
  .catch(e => {
    throw e;
  })

Bus Times

const transperth = require('transperthapi');
const Client = new transperth();
Client.busTimes('XXXXX') // Example Bus Stop Number
  .then(data => {
    if (data.error) throw new Error(data.error);

    console.log(data);

    /*
      { buses:
        [ { route: '000', time: 'XX:XX', destination: 'To XXX' },
          {...}],
        meta:
          { endpoint: 'http://...' } }
    */
  })
  .catch(e => {
    throw e;
  })

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free