-
Notifications
You must be signed in to change notification settings - Fork 0
/
scraper.js
74 lines (74 loc) · 2.05 KB
/
scraper.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
73
74
(async () => {
const axios = require("axios");
const username = "ethanneff";
const year = null;
const url = "https://leetcode.com/graphql";
const config = {
method: "POST",
headers: { "Content-Type": "application/json" },
data: JSON.stringify({
query: `query getUserProfile($username: String!, $year: Int) {
allQuestionsCount {
difficulty
count
}
matchedUser(username: $username) {
contributions {
points
}
profile {
reputation
ranking
}
userCalendar(year: $year) {
streak
totalActiveDays
dccBadges {
timestamp
badge {
name
icon
}
}
submissionCalendar
activeYears
}
submissionCalendar
submitStats {
acSubmissionNum {
difficulty
count
submissions
}
totalSubmissionNum {
difficulty
count
submissions
}
}
}
}`,
variables: { username, year },
}),
};
const {
data: { data },
} = await axios.request(url, config);
const output = {
solutions: {
problems: `${data.matchedUser.submitStats.totalSubmissionNum[0].count}`,
submissions: `${data.matchedUser.submitStats.totalSubmissionNum[0].submissions}`,
easy: `${data.matchedUser.submitStats.totalSubmissionNum[1].count}/${data.allQuestionsCount[1].count}`,
medium: `${data.matchedUser.submitStats.totalSubmissionNum[2].count}/${data.allQuestionsCount[2].count}`,
hard: `${data.matchedUser.submitStats.totalSubmissionNum[3].count}/${data.allQuestionsCount[3].count}`,
},
contributions: {
points: `${data.matchedUser.contributions.points}`,
ranking: `${data.matchedUser.profile.ranking}`,
reputation: `${data.matchedUser.profile.reputation}`,
},
username: username,
};
const formatted = JSON.stringify(output, null, 2);
return console.log(formatted);
})();