mtr-lines-scraper
v0.1.0
Published
Retrieve heavy rail and light rail lines and stations from the MTR company easily!
Downloads
3
Readme
mtr-lines-scraper
Retrieve heavy rail and light rail lines and stations from the MTR company easily!
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);
});