Skip to content

Commit 8a9f42f

Browse files
Feat: Added Logic
1 parent 5e41a79 commit 8a9f42f

File tree

3 files changed

+59
-7
lines changed

3 files changed

+59
-7
lines changed

package-lock.json

Lines changed: 18 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"description": "📊 Updates README with your Todoist stats",
55
"main": "todoist-update.js",
66
"dependencies": {
7-
"fs": "^0.0.1-security"
7+
"axios": "^0.20.0",
8+
"fs": "^0.0.1-security",
9+
"humanize-plus": "^1.8.2"
810
},
911
"devDependencies": {},
1012
"scripts": {

todoist-update.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,38 @@
1-
console.log("abhishek");
1+
const axios = require("axios");
2+
const Humanize = require("humanize-plus");
3+
4+
const TODOIST_API_KEY = "c1d1363fde9478b301eb037c4541abafb00ee07c";
5+
6+
async function main() {
7+
const stats = await axios(`https://api.todoist.com/sync/v8.3/completed/get_stats?token=${TODOIST_API_KEY}`);
8+
await updateReadme(stats.data);
9+
}
10+
11+
async function updateReadme(data) {
12+
13+
const lines = [];
14+
const { karma, completed_count, days_items, goals } = data;
15+
16+
const karmaPoint = [`🏅 ${Humanize.intComma(karma)} Karma Points`];
17+
lines.push(karmaPoint.join(" "));
18+
19+
const dailyGoal = [
20+
`🌸 Completed ${days_items[0].total_completed.toString()} tasks today`,
21+
];
22+
lines.push(dailyGoal.join(" "));
23+
24+
const totalTasks = [`✅ Completed ${Humanize.intComma(completed_count)} tasks so far`];
25+
lines.push(totalTasks.join(" "));
26+
27+
const longestStreak = [
28+
`⌛ Longest streak is ${goals.max_daily_streak.count} days`,
29+
];
30+
lines.push(longestStreak.join(" "));
31+
32+
if (lines.length == 0) return;
33+
console.log(lines.join("\n"));
34+
}
35+
36+
(async () => {
37+
await main();
38+
})();

0 commit comments

Comments
 (0)