From a00c7af2e0139c9f6a812afdc21085b571d20800 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Thu, 8 Dec 2022 10:46:29 +0000 Subject: [PATCH] Further edits to CORPUS --- src/utils/corpus.utils.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/utils/corpus.utils.js b/src/utils/corpus.utils.js index fdc4b03..8452cea 100644 --- a/src/utils/corpus.utils.js +++ b/src/utils/corpus.utils.js @@ -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 } \ No newline at end of file