Skip to content

Commit

Permalink
feat: add a script to get basic info from lc automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
S-N-O-R-L-A-X committed Feb 4, 2024
1 parent ccbf4dd commit 80bf9a9
Show file tree
Hide file tree
Showing 2 changed files with 484 additions and 429 deletions.
55 changes: 55 additions & 0 deletions getData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import fs from "fs/promises";

const year = new Date().getFullYear(), month = new Date().getMonth();

fetch("https://leetcode.cn/graphql/", {
method: "post",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"query": "\n query dailyQuestionRecords($year: Int!, $month: Int!) {\n dailyQuestionRecords(year: $year, month: $month) {\n date\n userStatus\n question {\n questionFrontendId\n title\n titleSlug\n translatedTitle\n }\n }\n}\n ",
"variables": {
"year": year,
"month": month + 1
},
"operationName": "dailyQuestionRecords"
}),
credentials: "include",
})
.then((res) => {
res.json().then((rb) => {
const questions = rb.data.dailyQuestionRecords;
fs.readFile(`./src/assets/${year}.json`, 'utf8').then(buf => {
const data=JSON.parse(buf)
if (data.daily.month.length<=month){
data.daily.month.push([]);
}
while(data.daily.month[month].length<questions.length){
const {date,question}=questions[data.daily.month[month].length-1];
const {frontendQuestionId,difficulty,titleCn,titleSlug,acRate}=question;
const record={
date,
no:frontendQuestionId,
name:titleCn,
slug:titleSlug,
difficulty,
rating,
method,
learn,
unknown,
acRate
}
data.daily.month[month].push(record);
}

fs.writeFile(`./src/assets/${year}.json`, JSON.stringify(data, null, 2));

}).catch(error => {
console.error(error);
});

})
});

Loading

0 comments on commit 80bf9a9

Please sign in to comment.