2022-12-06 01:20:43 +00:00
|
|
|
// 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`
|
|
|
|
|
2022-12-06 13:40:03 +00:00
|
|
|
const keys = require('/srv/keys/owlboard/keys.configs');
|
|
|
|
const axios = require('axios');
|
2022-12-07 01:28:00 +00:00
|
|
|
const zlib = require('zlib');
|
2022-12-06 13:40:03 +00:00
|
|
|
|
2022-12-07 13:22:00 +00:00
|
|
|
async function initCorpus(){ // EXPORT - Uses getCorpus() to download the CORPUS GZIP and then processes it.
|
|
|
|
let gzipData = await getCorpus();
|
|
|
|
console.log(gzipData);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getCorpus(){ // Download and return the GZIP file as an arraybuffer.
|
2022-12-06 13:40:03 +00:00
|
|
|
authHead = Buffer.from(`${keys.nr_user}:${keys.nr_pass}`).toString('base64');
|
2022-12-07 13:22:00 +00:00
|
|
|
const getReq = axios.create({
|
2022-12-06 13:40:03 +00:00
|
|
|
method: 'get',
|
2022-12-07 13:22:00 +00:00
|
|
|
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;
|
2022-12-06 13:40:03 +00:00
|
|
|
})
|
2022-12-07 13:22:00 +00:00
|
|
|
return download;
|
2022-12-06 13:40:03 +00:00
|
|
|
}
|
2022-12-06 01:20:43 +00:00
|
|
|
|
2022-12-07 14:23:25 +00:00
|
|
|
async function getCorpusAgain(){ //Try to get CORPUS then pipe to zlib and return uncompressed date
|
|
|
|
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
|
|
|
|
})
|
|
|
|
console.log(corpus); // This doesn't work but if console.logging from the function it prints.
|
|
|
|
}
|
|
|
|
|
2022-12-06 01:20:43 +00:00
|
|
|
async function cleanCorpus(){
|
2022-12-06 13:40:03 +00:00
|
|
|
// Clean the CORPUS as per the temporary Python Script
|
2022-12-06 01:20:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2022-12-07 14:23:25 +00:00
|
|
|
initCorpus,
|
|
|
|
getCorpusAgain
|
2022-12-06 01:20:43 +00:00
|
|
|
}
|