up convert from orgmode to tsv

This commit is contained in:
Tykayn 2023-04-18 22:54:38 +02:00 committed by tykayn
parent 48420bb7fe
commit e2fae4d826
4 changed files with 116 additions and 84 deletions

View File

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>

View File

@ -1,7 +1,6 @@
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
**/
@ -10,53 +9,67 @@ const outputAbsolutePath = '/home/tykayn/Nextcloud/ressources/social sorting/out
const outputFileNameJson = sourceFileName + '.json';
const sourceFilePath = "/home/tykayn/Nextcloud/ressources/social sorting/" + outputFileNameJson
const outputFileName = sourceFileName + '.tsv';
const outputFileName = outputAbsolutePath + sourceFileName + '.tsv';
// const separator_char= ";"
const separator_char = '\t'
const events = [headersTsv];
let counter = 0;
let max_count = 10000
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);
console.log(outputAbsolutePath + outputFileNameJson, json_content.tasks_list.length)
// do parse json content and add to tsv lines
data.forEach(item => {
json_content.tasks_list.forEach(item => {
if (counter < max_count) {
counter++;
console.log('item', item)
// TODO ajust lines
let newLine =
// item.visit_count + '\t' +
// item.title + '\t' +
// item.description + '\t' +
// item.preview_image_url + '\t' +
'' + '\t' +
// 'firefox_place' + '\t' +
'' + '\t' +
'' + '\t' +
// mydate + '\t' +
'' + '\t' +
'' + '\t'
url + '\t' +
''
// console.log('mydate',stamp, mydate)
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))
writeFileInOuputFolderFromJsonObject(outputFileName, events.join("\n"))
.then(r => console.log('r', r))
})
}

View File

@ -1,7 +1,6 @@
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
**/
@ -10,55 +9,69 @@ const outputAbsolutePath = '/home/tykayn/Nextcloud/ressources/social sorting/out
const outputFileNameJson = sourceFileName + '.json';
const sourceFilePath = "/home/tykayn/Nextcloud/ressources/social sorting/" + outputFileNameJson
const outputFileName = sourceFileName + '.tsv';
const outputFileName = outputAbsolutePath + sourceFileName + '.tsv';
// const separator_char= ";"
const separator_char = '\t'
const events = [headersTsv];
let counter = 0;
let max_count = 10000
let max_count = 2000
function parseJsonFile() {
fs.readFile(outputAbsolutePath + outputFileNameJson, 'utf8', function (err, data) {
fs.readFile(outputAbsolutePath + outputFileNameJson, 'utf8', function (err, data) {
if (err) {
return console.log(err);
}
const json_content = JSON.parse(data);
if (err) {
return console.log(err);
}
const json_content = JSON.parse(data);
console.log(outputAbsolutePath + outputFileNameJson, json_content.tasks_list.length)
// do parse json content and add to tsv lines
json_content.tasks_list.forEach(item => {
if (counter < max_count) {
counter++;
// do parse json content and add to tsv lines
data.forEach(item => {
// TODO ajust lines
if (counter < max_count) {
counter++;
console.log('item', item)
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 + '';
// TODO ajust lines
let newLine =
// item.visit_count + '\t' +
// item.title + '\t' +
// item.description + '\t' +
// item.preview_image_url + '\t' +
'' + '\t' +
// 'firefox_place' + '\t' +
'' + '\t' +
'' + '\t' +
// mydate + '\t' +
'' + '\t' +
'' + '\t'
url + '\t' +
''
// console.log('mydate',stamp, mydate)
events.push(newLine)
}
})
events.push(newLine)
}
})
console.log('events', events.length)
// writeFileInOuputFolderFromJsonObject(outputFileName, events.join("\n")).then(r => console.log('r', r))
console.log('events', events.length)
writeFileInOuputFolderFromJsonObject(outputFileName, events.join("\n"))
.then(r => console.log('r', r))
})
})
}
parseJsonFile()

View File

@ -1,33 +1,34 @@
import fs from "node-fs";
export const headersTsv = 'amount\t' +
'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'
'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'
const outputAbsolutePath = '/home/tykayn/Nextcloud/ressources/social sorting/output/';
export async function writeFileInOuputFolderFromJsonObject(fileName, jsonObjectThing) {
// console.log('statistics.dates', statistics.dates)
return await fs.writeFile(
`${outputAbsolutePath}${fileName}`,
JSON.stringify(jsonObjectThing),
"utf8",
(err) => {
if (err) {
console.log(`Error writing file: ${err}`);
} else {
console.log(`File ${fileName} is written successfully!`);
}
}
);
return await fs.writeFile(
`${fileName}`,
JSON.stringify(jsonObjectThing),
"utf8",
(err) => {
if (err) {
console.log(`Error writing file: ${err}`);
} else {
console.log(`File ${fileName} is written successfully!`);
}
}
);
}