convert to orgmode single file
This commit is contained in:
parent
f4ac8fcd22
commit
43d798085c
@ -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)
|
||||
@ -354,7 +362,7 @@ function exportToMarkdown(res) {
|
||||
markdownExportData += `\n# Export de toutes les ${jsonAllData.stats.listClosed.length} tâches fermées GTG \n `;
|
||||
markdownExportData += `\n `;
|
||||
|
||||
jsonAllData.stats.listClosed.map(elem=>{
|
||||
jsonAllData.stats.listClosed.map(elem => {
|
||||
dataTagsMd += `\n * ${elem.title} `;
|
||||
})
|
||||
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user