-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch.js
More file actions
20 lines (19 loc) · 1.79 KB
/
Copy pathfetch.js
File metadata and controls
20 lines (19 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const fs = require('fs');
const {default: axios} = require('axios');
const args = process.argv.slice(2);
const titleSlug = args[0];
axios
.post('https://leetcode.cn/graphql/', {
operationName: 'questionData',
variables: {
titleSlug
},
query:
'query questionData($titleSlug: String!) {\n question(titleSlug: $titleSlug) {\n questionId\n questionFrontendId\n categoryTitle\n boundTopicId\n title\n titleSlug\n content\n translatedTitle\n translatedContent\n isPaidOnly\n difficulty\n likes\n dislikes\n isLiked\n similarQuestions\n contributors {\n username\n profileUrl\n avatarUrl\n __typename\n }\n langToValidPlayground\n topicTags {\n name\n slug\n translatedName\n __typename\n }\n companyTagStats\n codeSnippets {\n lang\n langSlug\n code\n __typename\n }\n stats\n hints\n solution {\n id\n canSeeDetail\n __typename\n }\n status\n sampleTestCase\n metaData\n judgerAvailable\n judgeType\n mysqlSchemas\n enableRunCode\n envInfo\n book {\n id\n bookName\n pressName\n source\n shortDescription\n fullDescription\n bookImgUrl\n pressImgUrl\n productUrl\n __typename\n }\n isSubscribed\n isDailyQuestion\n dailyRecordStatus\n editorType\n ugcQuestionId\n style\n exampleTestcases\n jsonExampleTestcases\n __typename\n }\n}\n'
})
.then((res) => {
const {codeSnippets, questionFrontendId, titleSlug} = res.data.data.question;
const javascriptCode = codeSnippets.find((o) => o.lang === 'JavaScript').code;
const fileName = `${questionFrontendId}-${titleSlug}.js`;
fs.writeFileSync(fileName, javascriptCode);
});