/
index.js
36 lines (34 loc) · 1017 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { TodoistApi } from "@doist/todoist-api-typescript";
import "dotenv/config";
import fs from "fs";
const api = new TodoistApi(process.env.TODOIST_API_TOKEN);
const dateString = new Date().toISOString();
console.log(`\n☢️ TODOIST NUCLEAR OPTION ☢️\n`);
api
.getTasks()
.then((tasks) => {
console.log(`${tasks.length} task(s) found. Deleting...`);
fs.writeFileSync(
`./backups/${dateString}.json`,
JSON.stringify({ timestamp: dateString, tasks: tasks })
);
tasks.forEach((task) => {
api
.deleteTask(task.id)
.then((isSuccess) => {
let cutoff = 20;
let ellipsis = "";
if (task.content.length > cutoff) {
ellipsis = "...";
}
console.log(
`✓ Deleted task ${task.id} "${task.content.slice(
0,
15
)}${ellipsis}"`
);
})
.catch((error) => console.log(error));
});
})
.catch((error) => console.log(error));