traintimesPWA/tools/convert.js
2018-02-12 12:37:18 +00:00

61 lines
1.2 KiB
JavaScript

const { promisify } = require('util');
const jsonfile = require('jsonfile');
const logger = require('log4js').getLogger();
logger.level = 'trace';
const file = 'src/work/stations.json';
const outFile = 'src/work/stationsMap.json';
const readFile = promisify(jsonfile.readFile);
const writeFile = promisify(jsonfile.writeFile);
function doConvert(obj) {
const tempArray = [];
for(const item of obj.locations)
if ((item.lat !== 0) && (item.long !== 0)) {
// logger.debug(item.name);
tempArray.push([item.crs, item.name]);
}
//const locMap = new Map(tempArray);
// logger.debug(locMap);
writeFile(outFile, tempArray)
.then( () => {
logger.debug('Saved...');
}
)
.catch(err => {
logger.error('Json failed to save');
logger.warn(err);
});
}
readFile(file)
.then(obj => {
logger.info('json loaded....');
doConvert(obj);
})
.catch(err => {
logger.error('Json failed to load');
logger.warn(err);
});
/*
jsonfile.readFile(file, (err, obj) => {
if (err) {
logger.error('Json failed to load');
logger.warn(err);
}
else {
logger.info('Json loaded...');
doConvert(obj);
}
});
*/