org-report-stats/base_convert_to_activities_...

78 lines
2.4 KiB
JavaScript

import fs from "node-fs";
import {headersTsv, writeFileInOuputFolderFromJsonObject} from "./utils.mjs";
/**
convertir un json représentant toutes les tâches orgmode en un json rangé par dates
**/
const sourceFileName = 'export_all_tasks.org_parsed'
const outputAbsolutePath = '/home/tykayn/Nextcloud/ressources/social sorting/output/';
const outputFileNameJson = sourceFileName + '.json';
const sourceFilePath = "/home/tykayn/Nextcloud/ressources/social sorting/" + outputFileNameJson
const outputFileName = outputAbsolutePath + sourceFileName + '.tsv';
// const separator_char= ";"
const separator_char = '\t'
const events = [headersTsv];
let counter = 0;
let max_count = 2000
function parseJsonFile() {
fs.readFile(outputAbsolutePath + outputFileNameJson, 'utf8', function (err, data) {
if (err) {
return console.log(err);
}
const json_content = JSON.parse(data);
// do parse json content and add to tsv lines
json_content.tasks_list.forEach(item => {
if (counter < max_count) {
counter++;
// TODO ajust lines
let newLine;
newLine = "" +
// 0 'amount\t' +
'' + separator_char +
// 1 'content\t' +
item.corpus ?? '' + ' ' + separator_char +
// 2 'description\t' +
item.header + ' '+ separator_char +
// 3 'destination\t' +
'' + separator_char +
// 4 'end\t' +
item?.dates?.CLOSED+ ' ' + separator_char +
// 5 'kind of activity\t' +
'' + separator_char +
// 6 'person\t' +
'' + separator_char +
// 7 'place\t' +
'' + separator_char +
// 8 'source\t' +
'orgmode_all_tasks' + ' '+ separator_char +
// 9 'start\t' +
item?.dates?.CREATED + ' ' + separator_char +
// 10 'unique id\t' +
'' + separator_char +
// 11 'url\t'
'' + separator_char + '';
events.push(newLine)
}
})
console.log('events', events.length)
writeFileInOuputFolderFromJsonObject(outputFileName, events.join("\n"))
.then(r => console.log('r', r))
})
}
parseJsonFile()