38
loading...
This website collects cookies to deliver better user experience
My Todoist habitual tasks
Since LeetCode is using GraphQL, you would need to check out the “Payload” tab to see the GraphQL body
# HTTP POST to https://leetcode.com/graphql
query questionOfToday {
activeDailyCodingChallengeQuestion {
date
userStatus
link
question {
acRate
difficulty
freqBar
frontendQuestionId: questionFrontendId
isFavor
paidOnly: isPaidOnly
status
title
titleSlug
hasVideoSolution
hasSolution
topicTags {
name
id
slug
}
}
}
}
curl
command below to try it out yourself:curl --request POST \
--url https://leetcode.com/graphql \
--header 'Content-Type: application/json' \
--data '{"query":"query questionOfToday {\n\tactiveDailyCodingChallengeQuestion {\n\t\tdate\n\t\tuserStatus\n\t\tlink\n\t\tquestion {\n\t\t\tacRate\n\t\t\tdifficulty\n\t\t\tfreqBar\n\t\t\tfrontendQuestionId: questionFrontendId\n\t\t\tisFavor\n\t\t\tpaidOnly: isPaidOnly\n\t\t\tstatus\n\t\t\ttitle\n\t\t\ttitleSlug\n\t\t\thasVideoSolution\n\t\t\thasSolution\n\t\t\ttopicTags {\n\t\t\t\tname\n\t\t\t\tid\n\t\t\t\tslug\n\t\t\t}\n\t\t}\n\t}\n}\n","operationName":"questionOfToday"}'
// Just some constants
const LEETCODE_API_ENDPOINT = 'https://leetcode.com/graphql'
const DAILY_CODING_CHALLENGE_QUERY = `
query questionOfToday {
activeDailyCodingChallengeQuestion {
date
userStatus
link
question {
acRate
difficulty
freqBar
frontendQuestionId: questionFrontendId
isFavor
paidOnly: isPaidOnly
status
title
titleSlug
hasVideoSolution
hasSolution
topicTags {
name
id
slug
}
}
}
}`
// We can pass the JSON response as an object to our createTodoistTask later.
const fetchDailyCodingChallenge = async () => {
console.log(`Fetching daily coding challenge from LeetCode API.`)
const init = {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query: DAILY_CODING_CHALLENGE_QUERY }),
}
const response = await fetch(LEETCODE_API_ENDPOINT, init)
return response.json()
}
Authorization: Bearer xxx-your-todoist-api-token-xxx
to your HTTP request headercurl --request POST \
--url 'https://api.todoist.com/rest/v1/tasks?=' \
--header 'Authorization: Bearer xxx-your-todoist-api-token-xxx' \
--header 'Content-Type: application/json' \
--data '{
"content": "Buy a jar of peanut butter",
"due_string": "Today"
}'
const TODOIST_API_ENDPOINT = "https://api.todoist.com/rest/v1";
// Passing in the `question` object from fetchDailyCodingChallenge function
const createTodoistTask = async (question) => {
const questionInfo = question.data.activeDailyCodingChallengeQuestion;
const questionTitle = questionInfo.question.title;
const questionDifficulty = questionInfo.question.difficulty;
const questionLink = `https://leetcode.com${questionInfo.link}`;
console.log(`Creating Todoist task with title ${questionTitle}.`);
const body = {
content: `[${questionTitle}](${questionLink})`,
description: `Difficulty: ${questionDifficulty}`,
due_string: "Today",
priority: 4,
};
const init = {
method: "POST",
body: JSON.stringify(body),
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${TODOIST_API_TOKEN}`, // Set at environment variable
},
};
const response = await fetch(`${TODOIST_API_ENDPOINT}/tasks`, init);
return response.json();
};
npm install some-node-package
) that are running on Node.js would simply not work.Tip: Check out the supported packages and libraries here.
fetch
API.npm install -g @cloudflare/wrangler
addEventListener
function. For our use case, we will be using the ScheduledEvent API where we simply have to change our event from "fetch"
to "scheduled"
// Move the constants to const.js
const syncLeetCodeCodingChallenge = async (event) => {
const question = await fetchDailyCodingChallenge();
await createTodoistTask(question);
};
addEventListener("scheduled", (event) => {
// Change 'fetch' to 'scheduled'
event.waitUntil(syncLeetCodeCodingChallenge(event));
});
name = "<your-project-name>"
type = "webpack"
...
[triggers]
crons = ["1 0 * * *"]
# At terminal 1
miniflare
# At terminal 2
curl "http://localhost:8787/.mf/scheduled"
TODOIST_API_TOKEN
using wrangler secret put TODOIST_API_TOKEN
. You may find the newly added secret under 'Cloudflare Worker' → 'Settings' → 'Variables'. You can get your Todoist API token here.CF_API_TOKEN
into your GitHub repository secrets. You can create your API token from https://dash.cloudflare.com/profile/api-tokens using the Edit Cloudflare Workers
template.wrangler publish