bartjs
Version:
A client for interacting with the Bay Area Rapid Transit (BART) API
24 lines (19 loc) • 860 B
JavaScript
// Include dependencies
var Bart = require('../lib/bart');
var turf = require('@turf/turf');
var geojson = require('geojson');
var fs = require('fs');
// Take a Bart object and call the BART API to obtain
// a list of all stations from which we construct a
// GeoJSON object that is then written to file.
const updateStations = function(BartObj) {
BartObj.stationInfo({'cmd': 'stns'})
.then(stationJSON => {
const stations = stationJSON.stations.station;
// Create the GeoJSON object from the stations array
geoStations = geojson.parse(stations, { Point : ['gtfs_latitude',
'gtfs_longitude' ]});
// Call the JSON.stringify arguments to prettify what is written to file
fs.writeFileSync('stations.js', JSON.stringify(geoStations, null, 2), 'utf-8');
});
}