2023-04-18 21:59:16 +02:00
|
|
|
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
|
2023-04-18 22:54:38 +02:00
|
|
|
|
|
|
|
const outputFileName = outputAbsolutePath + sourceFileName + '.tsv';
|
|
|
|
|
|
|
|
// const separator_char= ";"
|
|
|
|
const separator_char = '\t'
|
2023-04-18 21:59:16 +02:00
|
|
|
|
|
|
|
const events = [headersTsv];
|
|
|
|
let counter = 0;
|
2023-04-18 22:54:38 +02:00
|
|
|
let max_count = 2000
|
2023-04-18 21:59:16 +02:00
|
|
|
|
|
|
|
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
|
2023-04-18 22:54:38 +02:00
|
|
|
json_content.tasks_list.forEach(item => {
|
2023-04-18 21:59:16 +02:00
|
|
|
|
|
|
|
if (counter < max_count) {
|
|
|
|
counter++;
|
|
|
|
|
|
|
|
// TODO ajust lines
|
2023-04-18 22:54:38 +02:00
|
|
|
|
|
|
|
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 + '';
|
|
|
|
|
2023-04-18 21:59:16 +02:00
|
|
|
events.push(newLine)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
console.log('events', events.length)
|
2023-04-18 22:54:38 +02:00
|
|
|
writeFileInOuputFolderFromJsonObject(outputFileName, events.join("\n"))
|
|
|
|
.then(r => console.log('r', r))
|
2023-04-18 21:59:16 +02:00
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
parseJsonFile()
|