// 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 initCorpus() { let gzipData = await getCorpusAgain(); console.log(gzipData); } async function getCorpus() { 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: 3000, headers: {'Authorization': `Basic ${authHead}`}, responseType: 'arraybuffer' }; return await axios.get(url, options).then(function (response){console.log(response.data);return response.data;}); } async function getCorpusAgain() { authHead = Buffer.from(`${keys.nr_user}:${keys.nr_pass}`).toString('base64'); const decomp = zlib.createGunzip(); const getReq = axios.create({ method: 'get', baseURL: 'https://datafeeds.networkrail.co.uk/ntrod/SupportingFileAuthenticate?type=CORPUS', timeout: 3000, headers: {'Authorization': `Basic ${authHead}`}, responseType: 'arraybuffer' }); let download = await getReq().then(function (response){ return response.data; }) zlib.gunzip(download, function (_err, output){ let string = output.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 init() { // PSUEDOCODE var zipData = await get(); var rawData = extract(zipData); var cleanData = clean(rawData) } async function get() { } async function extract() { } async function clean() { } module.exports = { initCorpus, getCorpusAgain, getCorpus, init }