Further edits to CORPUS

This commit is contained in:
Fred Boniface 2022-12-08 10:46:29 +00:00
parent 0d4b84c1ec
commit a00c7af2e0
1 changed files with 13 additions and 9 deletions

View File

@ -2,28 +2,32 @@
// 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(){ // EXPORT - Uses getCorpus() to download the CORPUS GZIP and then processes it.
let gzipData = await getCorpus();
let gzipData = await getCorpusAgain();
console.log(gzipData);
}
async function getCorpus(){ // Download and return the GZIP file as an arraybuffer.
authHead = Buffer.from(`${keys.nr_user}:${keys.nr_pass}`).toString('base64');
const getReq = axios.create({
const options = {
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;
})
return download;
};
let download = axios.get(options);
console.log(download);
}
async function getCorpusAgain(){ //Try to get CORPUS then pipe to zlib and return uncompressed date
@ -47,7 +51,6 @@ async function getCorpusAgain(){ //Try to get CORPUS then pipe to zlib and retur
//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.
}
async function cleanCorpus(){
@ -56,5 +59,6 @@ async function cleanCorpus(){
module.exports = {
initCorpus,
getCorpusAgain
getCorpusAgain,
getCorpus
}