0.1.0 • Published 5 years ago

mtr-lines-scraper v0.1.0

Weekly downloads
1
License
GPL-3.0
Repository
github
Last release
5 years ago

mtr-lines-scraper

Retrieve heavy rail and light rail lines and stations from the MTR company easily!

npm-version-badge npm-download-badge github-license-badge

Installation

$ npm install mtr-lines-scraper

Usage

Retrieve railway data from MTR

const { getRailwayDetails } = require("mtr-lines-scraper");

getRailwayDetails()
    .then((details) => {
        // Do whatever you want here.
        console.log(details.heavyRail);
        console.log(details.lightRail);
    });

Using railway data from local cache

Synchronous method

const { readFileSync } = require("fs");
const { getRailwayDetailsSync } = require("mtr-lines-scraper");

// Assume the cache does exist.
const cache = JSON.parse(readFileSync("cache.json", "utf8"));

// Retrieve railway details synchronously.
const details = getRailwayDetailsSync(cache);

// Do whatever you want here.
console.log(details.heavyRail);
console.log(details.lightRail);

Asynchronous method

const { readFileSync } = require("fs");
const { getRailwayDetailsSync } = require("mtr-lines-scraper");

// Assume the cache does exist.
const cache = JSON.parse(readFileSync("cache.json", "utf8"));

// Retrieve railway details asynchronously.
getRailwayDetails(cache)
    .then((details) => {
        // Do whatever you want here.
        console.log(details.heavyRail);
        console.log(details.lightRail);
    });