mtr-lines-scraper
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

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);
    });

Readme

Keywords

Package Sidebar

Install

npm i mtr-lines-scraper

Weekly Downloads

5

Version

0.1.0

License

GPL-3.0

Unpacked Size

71 kB

Total Files

37

Last publish

Collaborators

  • jasonhk