convert to orgmode single file

This commit is contained in:
Tykayn 2021-09-10 15:41:27 +02:00 committed by tykayn
parent f4ac8fcd22
commit 43d798085c

View File

@ -66,6 +66,7 @@ router.get('/', async function (req, res, next) {
console.log('================== calcul de stats désactivé dans index.js ================== ')
}
exportToMarkdown(res)
exportToOrgmode(res)
console.log('json files read')
res.render('index', {
title: "Conversion de GTG tâches",
@ -102,12 +103,14 @@ function computeData(jsonConvertedData) {
jsonAllData.all = gtgData
jsonAllData.stats = {
tasksCount : counterOfTasks.length,
tasksCount: counterOfTasks.length,
// tasksCount: 0,
tasksClosed: 0,
tasksOpen: 0,
maxTasksCountPerTag: 0,
listTags: [],
tagByKey: {},
listAll: [],
listOpen: [],
listOpenWeekly: [],
listOpenMonthly: [],
@ -122,12 +125,17 @@ function computeData(jsonConvertedData) {
jsonAllData.stats.listTags = gtgData.taglist[0].tag
console.log('tasks', gtgData.tasklist[0].task);
for (let tagItem of jsonAllData.stats.listTags) {
jsonAllData.stats.tagByKey[tagItem["$"].id] = tagItem["$"]
}
for (let taskItem of gtgData.tasklist[0].task) {
// count open and closed tasks
let now = new Date()
jsonAllData.stats.listAll.push(taskItem)
if (taskItem['$'].status == 'Active') {
jsonAllData.stats.listOpen.push(taskItem)
let addeddate = new Date(taskItem.addeddate)
@ -342,20 +350,20 @@ function exportToMarkdown(res) {
markdownExportData += `\n `;
jsonAllData.stats.listOpen.map(elem => {
dataTagsMd += `\n## ${elem.title} `;
dataTagsMd += `\n statut : ${elem['$'].status} `;
dataTagsMd += `\n créé le : ${elem.addeddate} `;
dataTagsMd += `\n modifié le : ${elem.modified} `;
dataTagsMd += `\n prévu pour : ${elem.duedate | ''} `;
dataTagsMd += `\n ${elem.content} `;
dataTagsMd += `\n## ${elem.title} `;
dataTagsMd += `\n statut : ${elem['$'].status} `;
dataTagsMd += `\n créé le : ${elem.addeddate} `;
dataTagsMd += `\n modifié le : ${elem.modified} `;
dataTagsMd += `\n prévu pour : ${elem.duedate | ''} `;
dataTagsMd += `\n ${elem.content} `;
})
markdownExportData += `\n--- `;
markdownExportData += `\n `;
markdownExportData += `\n# Export de toutes les ${jsonAllData.stats.listClosed.length} tâches fermées GTG \n `;
markdownExportData += `\n `;
jsonAllData.stats.listClosed.map(elem=>{
dataTagsMd += `\n * ${elem.title} `;
jsonAllData.stats.listClosed.map(elem => {
dataTagsMd += `\n * ${elem.title} `;
})
markdownExportData += `\n `;
@ -391,6 +399,54 @@ function exportToMarkdown(res) {
}
function exportToOrgmode(res) {
console.log('jsonAllData.stats.tagByKey', jsonAllData.stats.tagByKey);
let orgmodeContent = `# Tâches exportées
`;
jsonAllData.stats.listAll.map(elem => {
orgmodeContent += `\n*`;
if(elem.$.status === 'Active'){
orgmodeContent += `TODO`;
}
if(elem.$.status === 'Done'){
orgmodeContent += `DONE`;
}
if(elem.$.status === 'Dismiss'){
orgmodeContent += `CANCELED`;
}
orgmodeContent += ` ${elem.title} `;
if (elem.tags[0]) {
elem.tags[0].tag.map(tag => {
// console.log('tag', tag);
// console.log('jsonAllData.stats.tagByKey[tag]', jsonAllData.stats.tagByKey[tag]);
if (tag) {
orgmodeContent += `:${jsonAllData.stats.tagByKey[tag].name}: `;
// orgmodeContent += `:${tag}: `;
}
})
}
})
// write file to disk
fs.writeFile(`output/export_tasks.org`, orgmodeContent, `utf8`, (err) => {
if (err) {
console.log(`Error writing file: ${err}`);
res.send(err)
} else {
console.log(`File \`output/export_tasks.org\` is written successfully!`);
}
});
}
/**
* transformToJson
* @param xml