org-report-stats/utils.mjs

37 lines
843 B
JavaScript
Raw Normal View History

2023-09-21 22:00:15 +02:00
import fs from 'node-fs'
2023-04-18 21:59:16 +02:00
2023-03-15 22:00:07 +01:00
export const headersTsv = 'amount\t' +
2023-04-18 22:54:38 +02:00
'content\t' +
'description\t' +
'destination\t' +
'end\t' +
'kind of activity\t' +
'person\t' +
'place\t' +
'source\t' +
'start\t' +
'unique id\t' +
'url\t'
2023-04-18 21:59:16 +02:00
2023-09-21 22:00:15 +02:00
const outputAbsolutePath = '/home/tykayn/Nextcloud/ressources/social sorting/output/'
2023-04-18 21:59:16 +02:00
2023-09-21 22:00:15 +02:00
export async function writeFileInOuputFolderFromJsonObject (fileName, jsonObjectThing) {
2023-04-18 21:59:16 +02:00
2023-04-18 22:54:38 +02:00
// console.log('statistics.dates', statistics.dates)
2023-09-21 22:00:15 +02:00
let fullpath = `${outputAbsolutePath}${fileName}`
2023-04-18 21:59:16 +02:00
2023-04-18 22:54:38 +02:00
return await fs.writeFile(
2023-09-21 22:00:15 +02:00
fullpath,
2023-09-21 18:15:45 +02:00
JSON.stringify(jsonObjectThing, null, 2),
// JSON.stringify(jsonObjectThing).replace('\n',''),
2023-09-21 22:00:15 +02:00
'utf8',
2023-04-18 22:54:38 +02:00
(err) => {
if (err) {
2023-09-21 22:00:15 +02:00
console.log(`Error writing file: ${err}`)
2023-04-18 22:54:38 +02:00
} else {
2023-09-21 22:00:15 +02:00
console.log(`File ${fileName} is written successfully! \n\n ${fullpath}`)
2023-04-18 22:54:38 +02:00
}
}
2023-09-21 22:00:15 +02:00
)
2023-04-18 21:59:16 +02:00
}