-
Notifications
You must be signed in to change notification settings - Fork 1
/
dailylc.js
72 lines (68 loc) · 1.75 KB
/
dailylc.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const axios = require("axios");
async function fetchData() {
try {
const response = await axios.post(
"https://leetcode.com/graphql",
{
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
}
content
}
}
}`,
},
{
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
}
);
const data = response.data;
const question = data.data.activeDailyCodingChallengeQuestion.question;
const result = {
date: data.data.activeDailyCodingChallengeQuestion.date,
userStatus: data.data.activeDailyCodingChallengeQuestion.userStatus,
link: data.data.activeDailyCodingChallengeQuestion.link,
question: {
acRate: question.acRate,
difficulty: question.difficulty,
freqBar: question.freqBar,
title: question.title,
titleSlug: question.titleSlug,
topicTags: question.topicTags.map((tag) => ({
name: tag.name,
})),
content: question.content,
},
};
return result;
} catch (error) {
// Handle any errors that occur during the request
console.error(error);
return null;
}
}
module.exports = {
fetchData: fetchData,
};