// Get CORPUS data from Network Rail and format the data for OwlBoard // Username and password 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 options = { method: 'get', baseURL: 'https://datafeeds.networkrail.co.uk/ntrod/SupportingFileAuthenticate?type=CORPUS', timeout: 3000, headers: {'Authorization': `Basic ${authHead}`}, responseType: 'arraybuffer' }; let download = axios.get(options); console.log(download); } 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() { } async function get() { } async function extract() { } async function clean() { } module.exports = { initCorpus, getCorpusAgain, getCorpus }