Skip to content
Snippets Groups Projects
Commit 7e61182e authored by i-vall's avatar i-vall
Browse files

Conversion of data to JSON

parent 41756316
No related branches found
No related tags found
No related merge requests found
......@@ -32,7 +32,8 @@ async function start(fields) {
console.log('\njavaxfaces2:\n',javaxFaces2)
await preGetData(javaxFaces2)
await getData(javaxFaces2)
const data = await getData(javaxFaces2)
await toJSON(data)
log('info', 'Saving data to Cozy')
}
......@@ -150,6 +151,7 @@ async function getData(javaxFaces){
const response = await rp(dataRequest)
var data = /donneesCourante = ".+"/.exec(response);
console.log(data[0])
return data[0]
} catch(error) {
console.log(error)
......@@ -184,3 +186,15 @@ async function preGetData(javaxFaces){ //POURQUOI? ... à voir
}
}
async function toJSON(data){
const dataArray = data.slice(19,-1).split(',')
console.log(dataArray)
var n = dataArray.length
const res = dataArray.reduce((accumulator, currentValue) => {
n --
return accumulator + '{ "value": ' + currentValue + ', "time": ' + moment().subtract(n, 'day').format('DD/MM/YYYY') + '},'
}, '')
return res
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment