mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-05 04:11:26 +08:00
feat(route): leetcode.cn daily question (#10397)
This commit is contained in:
@@ -307,7 +307,7 @@ Subscribe to the updates (threads and submission) from a paritcular Hacker News
|
|||||||
|
|
||||||
### Daily Question
|
### Daily Question
|
||||||
|
|
||||||
<RouteEn author="NavePnow" example="/leetcode/dailyquestion/en" path="/leetcode/dailyquestion/en"/>
|
<RouteEn author="NavePnow" example="/leetcode/dailyquestion/en" path="/leetcode/dailyquestion/:lang" :paramsDesc="['site, Chines(cn) and Engligh(en)']"/>
|
||||||
|
|
||||||
## Linux Patchwork
|
## Linux Patchwork
|
||||||
|
|
||||||
|
|||||||
@@ -449,7 +449,7 @@ GitHub 官方也提供了一些 RSS:
|
|||||||
|
|
||||||
### 每日一题
|
### 每日一题
|
||||||
|
|
||||||
<Route author="NavePnow" example="/leetcode/dailyquestion/en" path="/leetcode/dailyquestion/en"/>
|
<Route author="NavePnow" example="/leetcode/dailyquestion/en" path="/leetcode/dailyquestion/:lang" :paramsDesc="['站点,中文(cn)和英文(en)']"/>
|
||||||
|
|
||||||
## LinkedKeeper
|
## LinkedKeeper
|
||||||
|
|
||||||
|
|||||||
115
lib/v2/leetcode/dailyquestion-cn.js
Normal file
115
lib/v2/leetcode/dailyquestion-cn.js
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
const got = require('@/utils/got');
|
||||||
|
const { art } = require('@/utils/render');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const host = 'https://leetcode.cn';
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const question = {
|
||||||
|
date: '',
|
||||||
|
link: '',
|
||||||
|
titleSlug: '',
|
||||||
|
content: '',
|
||||||
|
frontedId: '',
|
||||||
|
difficulty: '',
|
||||||
|
tags: '',
|
||||||
|
};
|
||||||
|
const url = host + '/graphql';
|
||||||
|
const dailyQuestionPayload = {
|
||||||
|
query: `query questionOfToday {
|
||||||
|
todayRecord {
|
||||||
|
date
|
||||||
|
question {
|
||||||
|
frontendQuestionId: questionFrontendId
|
||||||
|
titleSlug
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} `,
|
||||||
|
variables: {},
|
||||||
|
};
|
||||||
|
const dailyQuestionResponse = await got({
|
||||||
|
method: 'post',
|
||||||
|
url,
|
||||||
|
headers: {
|
||||||
|
'content-type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(dailyQuestionPayload),
|
||||||
|
});
|
||||||
|
const data = dailyQuestionResponse.data.data.todayRecord[0];
|
||||||
|
question.date = data.date;
|
||||||
|
question.titleSlug = data.question.titleSlug;
|
||||||
|
question.link = host + '/problems/' + question.titleSlug;
|
||||||
|
|
||||||
|
const detailsPayload = {
|
||||||
|
operationName: 'questionData',
|
||||||
|
query: `query questionData($titleSlug: String!) {
|
||||||
|
question(titleSlug: $titleSlug) {
|
||||||
|
questionId
|
||||||
|
questionFrontendId
|
||||||
|
title
|
||||||
|
titleSlug
|
||||||
|
content
|
||||||
|
translatedTitle
|
||||||
|
translatedContent
|
||||||
|
difficulty
|
||||||
|
topicTags {
|
||||||
|
name
|
||||||
|
slug
|
||||||
|
translatedName
|
||||||
|
__typename
|
||||||
|
}
|
||||||
|
__typename
|
||||||
|
}
|
||||||
|
}`,
|
||||||
|
variables: {
|
||||||
|
titleSlug: question.titleSlug,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const detailsResponse = await got({
|
||||||
|
method: 'post',
|
||||||
|
url,
|
||||||
|
headers: {
|
||||||
|
'content-type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(detailsPayload),
|
||||||
|
});
|
||||||
|
const emoji = {
|
||||||
|
Medium: '🟡',
|
||||||
|
Easy: '🟢',
|
||||||
|
Hard: '🔴',
|
||||||
|
};
|
||||||
|
|
||||||
|
const details = detailsResponse.data.data.question;
|
||||||
|
question.content = details.translatedContent;
|
||||||
|
question.frontedId = details.questionFrontendId;
|
||||||
|
question.difficulty = emoji[details.difficulty];
|
||||||
|
|
||||||
|
let topicTags = details.topicTags;
|
||||||
|
topicTags = topicTags.map((item) => {
|
||||||
|
let slug = '#' + item.slug;
|
||||||
|
slug = slug.replaceAll('-', '_');
|
||||||
|
return slug;
|
||||||
|
});
|
||||||
|
question.tags = topicTags.join(' ');
|
||||||
|
|
||||||
|
const rssData = {
|
||||||
|
title: question.frontedId + '.' + question.titleSlug,
|
||||||
|
description: art(path.join(__dirname, 'templates/question-description.art'), {
|
||||||
|
question,
|
||||||
|
}),
|
||||||
|
link: question.link,
|
||||||
|
};
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title: 'LeetCode 每日一题',
|
||||||
|
link: 'https://leetcode.cn',
|
||||||
|
description: 'Leetcode 每日一题',
|
||||||
|
item: [
|
||||||
|
{
|
||||||
|
title: rssData.title,
|
||||||
|
description: rssData.description + question.content,
|
||||||
|
link: rssData.link,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
'/dailyquestion/en': ['NavePnow'],
|
'/dailyquestion/en': ['NavePnow'],
|
||||||
|
'/dailyquestion/cn': ['NavePnow'],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
module.exports = function (router) {
|
module.exports = function (router) {
|
||||||
router.get('/dailyquestion/en', require('./dailyquestion-en'));
|
router.get('/dailyquestion/en', require('./dailyquestion-en'));
|
||||||
|
router.get('/dailyquestion/cn', require('./dailyquestion-cn'));
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user