Getting there
This commit is contained in:
parent
7eac21411a
commit
0d4b84c1ec
@ -5,7 +5,6 @@
|
|||||||
const keys = require('/srv/keys/owlboard/keys.configs');
|
const keys = require('/srv/keys/owlboard/keys.configs');
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
const zlib = require('zlib');
|
const zlib = require('zlib');
|
||||||
const fs = require('fs');
|
|
||||||
|
|
||||||
async function initCorpus(){ // EXPORT - Uses getCorpus() to download the CORPUS GZIP and then processes it.
|
async function initCorpus(){ // EXPORT - Uses getCorpus() to download the CORPUS GZIP and then processes it.
|
||||||
let gzipData = await getCorpus();
|
let gzipData = await getCorpus();
|
||||||
@ -27,10 +26,35 @@ async function getCorpus(){ // Download and return the GZIP file as an arraybuff
|
|||||||
return download;
|
return download;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.
|
||||||
|
}
|
||||||
|
|
||||||
async function cleanCorpus(){
|
async function cleanCorpus(){
|
||||||
// Clean the CORPUS as per the temporary Python Script
|
// Clean the CORPUS as per the temporary Python Script
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
initCorpus
|
initCorpus,
|
||||||
|
getCorpusAgain
|
||||||
}
|
}
|
Reference in New Issue
Block a user