1.0.3 • Published 9 years ago

traintrack v1.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

TrainTrack

Simple node.js module for scraping and parsing SydneyTrains timetable data for analysis.

Install

$ npm install traintrack

Usage

var tt = require('traintrack');

Example

This example code extracts timetable data for the "North Shore & Northern Line", in the "Berowra to Parramatta"-direction, and then converts it into CSV format.

tt.getBody('ns', 0, function(html){
    tt.parseBody(html, function(data){
        tt.toCSV(data, function(string){
            console.log(string);
        });
    });
});

Timetables

Currently supported timetables for querying.

CodeLineTimetable
nsT1North Shore & Northern Line
ntT1Northern Line
wtT1Western Line
ehT2Airport Line
iwT2Inner West & South Line
bkT3Bankstown Line
ilT4Eastern Suburbs & Illawarra Line
cuT5Cumberland Line
clT6Carlingford Line
opT7Olympic Park Line

Data Format

  • All stations are enumerated from stations.json.
  • The data object holds two arrays, stations and times, respectively.
  • Times are stored as rows per station, each row is equal in length.
stationstimes
s[0]t[0][0] t[0][1] t[0][2] ...
s[1]t[1][0] t[1][1] t[1][2] ...
s[2]t[2][0] t[2][1] t[2][2] ...
s[3]t[3][0] t[3][1] t[3][2] ...
{
	// array of stations
	s: [ "Station1", "Station2", ... ]
	// multidimensional array of times
	t: [ [ "00:00", "00:10", ... ], ... ]
}

API Reference

Retrieve a Timetable

  • line (string): Code of timetable to retrieve (refer to above table.)
  • direction (integer): 0 or 1 for timetable train direction.
  • callback (function(html)): Callback returns html body through html parameter.
tt.getBody(line, direction, callback(html));

Parse the HTML

  • html (string): HTML body of timetable source..
  • callback (function(data)): Callback returns object of parsed timetable source through data parameter.
tt.parseBody(html, callback(data));

Output as CSV

  • data (object): Data object returned from HTML parsing.
  • callback (function(data)): Callback returns the CSV encoded string of object through string parameter.
tt.toCSV(data, callback(string));
1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago