// Get CORPUS data from Network Rail and format the data for OwlBoard // Network Rail Datafeed user and pass must be stored in `/srv/keys/owlboard/keys.config.js` // FUNCTIONS // init() : Exported: Uses the internal functions to return a clean CORPUS file. // get() : Get the CORPUS data from Network Rail as a gzip file. // extract(): Extract the CORPUS JSON file from the GZIP file. // clean() : Cleans the CORPUS data, removing unneccesary keys from the data. const keys = require('/srv/keys/owlboard/keys.configs'); const axios = require('axios'); const zlib = require('zlib'); async function init() { var gzipData = await get(); console.log(gzipData); var rawData = await extract(gzipData); console.log(rawData); var cleanData = await clean(rawData); console.log(cleanData) return cleanData; } async function get() { authHead = Buffer.from(`${keys.nr_user}:${keys.nr_pass}`).toString('base64'); const url = 'https://datafeeds.networkrail.co.uk/ntrod/SupportingFileAuthenticate?type=CORPUS' const options = { method: 'get', timeout: 20000, headers: {'Authorization': `Basic ${authHead}`}, responseType: 'arraybuffer' }; var { output } = await axios.get(url, options) console.log(output) return output; } async function extract(input) { var { data } = zlib.Gunzip(input); let string = data.toString() let obj = JSON.parse(string) //console.log(obj); return obj; // Find out how to get data out of callback -> See pinned tab on laptop2.ws } async function clean() { return "Empty Function: clean()" } module.exports = { init }