Skip to content

Instantly share code, notes, and snippets.

@mitul45
Created December 20, 2023 17:42
Show Gist options
  • Save mitul45/5028226c709f2c6e555c40b28acdd565 to your computer and use it in GitHub Desktop.
Save mitul45/5028226c709f2c6e555c40b28acdd565 to your computer and use it in GitHub Desktop.
Convert TickTick backup JSON created by `thesamim/TickTickSync` Obsidian plugin to a format that TickTick accepts for import
const fs = require('fs');
const inputFilePath = "./ticktick.json"
const outputFilePath = "./ticktick-output.csv"
const blob = JSON.parse(fs.readFileSync(inputFilePath));
let output = `"Date: 2023-12-20+0000"
"Version: 7.1"
"Status:
0 Normal
1 Completed
2 Archived"
"Folder Name","List Name","Title","Kind","Tags","Content","Is Check list","Start Date","Due Date","Reminder","Repeat","Priority","Status","Created Time","Completed Time","Order","Timezone","Is All Day","Is Floating","Column Name","Column Order","View Mode","taskId","parentId"
`;
const projectMap = {
inbox118164049: "Inbox"
};
blob.projectProfiles.forEach(profile => {
projectMap[profile.id] = profile.name;
})
const getReminder = row => {
if(Array.isArray(row.reminders) && row.reminders.length > 0) {
return row.reminders[0].trigger.split(":")[1].replaceAll(".000", "");
}
return "";
}
const isCheckList = row => row.kind === 'CHECKLIST' && row.items.length > 0;
const isCheckListYN = row => {
return row.kind === 'CHECKLIST' ? 'Y' : 'N';
}
const content = row => {
if (isCheckList(row)) {
let c = "";
row.items.forEach((item) => {
c += `
▪${item.title}`
})
return c;
} else {
return row.content ? row.content : "";
}
}
blob.syncTaskBean.update.forEach((item,index) => {
const row = `"","${projectMap[item.projectId]}","${item.title}","${item.kind}","","${content(item)}","${isCheckListYN(item)}","${item.startDate ? item.startDate.replaceAll(".000", "") : ""}","${item.dueDate ? item.dueDate.replaceAll(".000", "") : ""}","${getReminder(item)}","${item.repeatFlag? item.repeatFlag.split(":")[1] : ""}","0","${item.status}","${item.createdTime}","${item.completedTime ? item.completedTime.replaceAll(".000", ""): ""}","${item.sortOrder}","Europe/Amsterdam","${item.isAllDay? "true": "false"}","false",,,"list","${index}",""
`;
output += row;
})
try {
fs.writeFileSync(outputFilePath, output, 'utf8');
console.log('Data successfully saved to disk');
} catch (error) {
console.log('An error has occurred ', error);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment