up convert from orgmode to tsv
This commit is contained in:
parent
48420bb7fe
commit
e2fae4d826
|
@ -0,0 +1,5 @@
|
||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<state>
|
||||||
|
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||||
|
</state>
|
||||||
|
</component>
|
|
@ -1,7 +1,6 @@
|
||||||
import fs from "node-fs";
|
import fs from "node-fs";
|
||||||
import {headersTsv, writeFileInOuputFolderFromJsonObject} from "./utils.mjs";
|
import {headersTsv, writeFileInOuputFolderFromJsonObject} from "./utils.mjs";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
convertir un json représentant toutes les tâches orgmode en un json rangé par dates
|
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 outputFileNameJson = sourceFileName + '.json';
|
||||||
|
|
||||||
const sourceFilePath = "/home/tykayn/Nextcloud/ressources/social sorting/" + outputFileNameJson
|
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];
|
const events = [headersTsv];
|
||||||
let counter = 0;
|
let counter = 0;
|
||||||
let max_count = 10000
|
let max_count = 2000
|
||||||
|
|
||||||
function parseJsonFile() {
|
function parseJsonFile() {
|
||||||
|
|
||||||
fs.readFile(outputAbsolutePath + outputFileNameJson, 'utf8', function (err, data) {
|
fs.readFile(outputAbsolutePath + outputFileNameJson, 'utf8', function (err, data) {
|
||||||
|
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return console.log(err);
|
return console.log(err);
|
||||||
}
|
}
|
||||||
const json_content = JSON.parse(data);
|
const json_content = JSON.parse(data);
|
||||||
console.log(outputAbsolutePath + outputFileNameJson, json_content.tasks_list.length)
|
|
||||||
|
|
||||||
|
|
||||||
// do parse json content and add to tsv lines
|
// do parse json content and add to tsv lines
|
||||||
data.forEach(item => {
|
json_content.tasks_list.forEach(item => {
|
||||||
|
|
||||||
if (counter < max_count) {
|
if (counter < max_count) {
|
||||||
counter++;
|
counter++;
|
||||||
console.log('item', item)
|
|
||||||
|
|
||||||
// TODO ajust lines
|
// TODO ajust lines
|
||||||
let newLine =
|
|
||||||
// item.visit_count + '\t' +
|
let newLine;
|
||||||
// item.title + '\t' +
|
newLine = "" +
|
||||||
// item.description + '\t' +
|
// 0 'amount\t' +
|
||||||
// item.preview_image_url + '\t' +
|
'' + separator_char +
|
||||||
'' + '\t' +
|
// 1 'content\t' +
|
||||||
// 'firefox_place' + '\t' +
|
item.corpus ?? '' + ' ' + separator_char +
|
||||||
'' + '\t' +
|
// 2 'description\t' +
|
||||||
'' + '\t' +
|
item.header + ' '+ separator_char +
|
||||||
// mydate + '\t' +
|
// 3 'destination\t' +
|
||||||
'' + '\t' +
|
'' + separator_char +
|
||||||
'' + '\t'
|
// 4 'end\t' +
|
||||||
url + '\t' +
|
item?.dates?.CLOSED+ ' ' + separator_char +
|
||||||
''
|
// 5 'kind of activity\t' +
|
||||||
// console.log('mydate',stamp, mydate)
|
'' + 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)
|
events.push(newLine)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log('events', events.length)
|
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))
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import fs from "node-fs";
|
import fs from "node-fs";
|
||||||
import {headersTsv, writeFileInOuputFolderFromJsonObject} from "./utils.mjs";
|
import {headersTsv, writeFileInOuputFolderFromJsonObject} from "./utils.mjs";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
convertir un json représentant toutes les tâches orgmode en un json rangé par dates
|
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 outputFileNameJson = sourceFileName + '.json';
|
||||||
|
|
||||||
const sourceFilePath = "/home/tykayn/Nextcloud/ressources/social sorting/" + outputFileNameJson
|
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];
|
const events = [headersTsv];
|
||||||
let counter = 0;
|
let counter = 0;
|
||||||
let max_count = 10000
|
let max_count = 2000
|
||||||
|
|
||||||
function parseJsonFile() {
|
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) {
|
// do parse json content and add to tsv lines
|
||||||
return console.log(err);
|
json_content.tasks_list.forEach(item => {
|
||||||
}
|
|
||||||
const json_content = JSON.parse(data);
|
|
||||||
console.log(outputAbsolutePath + outputFileNameJson, json_content.tasks_list.length)
|
|
||||||
|
|
||||||
|
if (counter < max_count) {
|
||||||
|
counter++;
|
||||||
|
|
||||||
// do parse json content and add to tsv lines
|
// TODO ajust lines
|
||||||
data.forEach(item => {
|
|
||||||
|
|
||||||
if (counter < max_count) {
|
let newLine;
|
||||||
counter++;
|
newLine = "" +
|
||||||
console.log('item', item)
|
// 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
|
events.push(newLine)
|
||||||
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)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
console.log('events', events.length)
|
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))
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
parseJsonFile()
|
parseJsonFile()
|
||||||
|
|
49
utils.mjs
49
utils.mjs
|
@ -1,33 +1,34 @@
|
||||||
import fs from "node-fs";
|
import fs from "node-fs";
|
||||||
|
|
||||||
export const headersTsv = 'amount\t' +
|
export const headersTsv = 'amount\t' +
|
||||||
'content\t' +
|
'content\t' +
|
||||||
'description\t' +
|
'description\t' +
|
||||||
'destination\t' +
|
'destination\t' +
|
||||||
'end\t' +
|
'end\t' +
|
||||||
'kind of activity\t' +
|
'kind of activity\t' +
|
||||||
'person\t' +
|
'person\t' +
|
||||||
'place\t' +
|
'place\t' +
|
||||||
'source\t' +
|
'source\t' +
|
||||||
'start\t' +
|
'start\t' +
|
||||||
'unique id\t' +
|
'unique id\t' +
|
||||||
'url\t'
|
'url\t'
|
||||||
|
|
||||||
|
|
||||||
|
const outputAbsolutePath = '/home/tykayn/Nextcloud/ressources/social sorting/output/';
|
||||||
|
|
||||||
export async function writeFileInOuputFolderFromJsonObject(fileName, jsonObjectThing) {
|
export async function writeFileInOuputFolderFromJsonObject(fileName, jsonObjectThing) {
|
||||||
|
|
||||||
|
// console.log('statistics.dates', statistics.dates)
|
||||||
|
|
||||||
return await fs.writeFile(
|
return await fs.writeFile(
|
||||||
`${outputAbsolutePath}${fileName}`,
|
`${fileName}`,
|
||||||
JSON.stringify(jsonObjectThing),
|
JSON.stringify(jsonObjectThing),
|
||||||
"utf8",
|
"utf8",
|
||||||
(err) => {
|
(err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(`Error writing file: ${err}`);
|
console.log(`Error writing file: ${err}`);
|
||||||
} else {
|
} else {
|
||||||
console.log(`File ${fileName} is written successfully!`);
|
console.log(`File ${fileName} is written successfully!`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue