mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-12 16:20:27 +08:00
feat: add kaggle 讨论区 (#3275)
This commit is contained in:
@@ -154,6 +154,17 @@ GitHub 官方也提供了一些 RSS:
|
|||||||
|
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
|
## kaggle
|
||||||
|
|
||||||
|
### Discussion
|
||||||
|
|
||||||
|
<Route author="LogicJake" example="/kaggle/discussion/387811/active" path="/kaggle/discussion/:forumId/:sort?" :paramsDesc="['讨论区 id, 打开网页请求, 搜索 forumId', '排序方式见下表, 默认为 hot']">
|
||||||
|
|
||||||
|
| hot | recent | new | top | active |
|
||||||
|
| ------- | --------------- | --------------- | ---------- | ------------- |
|
||||||
|
| Hotness | Recent Comments | Recently Posted | Most Votes | Most Comments |
|
||||||
|
|
||||||
|
</Route>
|
||||||
## LeetCode
|
## LeetCode
|
||||||
|
|
||||||
### 文章
|
### 文章
|
||||||
|
|||||||
@@ -1847,4 +1847,7 @@ router.get('/4gamers/tag/:tag', require('./routes/4gamers/tag'));
|
|||||||
// 大麦网
|
// 大麦网
|
||||||
router.get('/damai/activity/:city/:category/:subcategory/:keyword?', require('./routes/damai/activity'));
|
router.get('/damai/activity/:city/:category/:subcategory/:keyword?', require('./routes/damai/activity'));
|
||||||
|
|
||||||
|
// kaggle
|
||||||
|
router.get('/kaggle/discussion/:forumId/:sort?', require('./routes/kaggle/discussion'));
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
69
lib/routes/kaggle/discussion.js
Normal file
69
lib/routes/kaggle/discussion.js
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
const got = require('@/utils/got');
|
||||||
|
const url = require('url');
|
||||||
|
|
||||||
|
const rootUrl = 'https://www.kaggle.com/';
|
||||||
|
|
||||||
|
const sortCodes = {
|
||||||
|
hot: 'Hotness',
|
||||||
|
recent: 'Recent Comments',
|
||||||
|
new: 'Recently Posted',
|
||||||
|
top: 'Most Votes',
|
||||||
|
active: 'Most Comments',
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const sort = ctx.params.sort || 'hot';
|
||||||
|
const forumId = ctx.params.forumId;
|
||||||
|
const sortText = sortCodes[sort];
|
||||||
|
|
||||||
|
const response = await got({
|
||||||
|
method: 'get',
|
||||||
|
url: `https://www.kaggle.com/forums/${forumId}/topics.json?sortBy=${sort}&group=all&page=1&pageSize=20&category=all`,
|
||||||
|
headers: {
|
||||||
|
Referer: rootUrl,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const topics = response.data.topics;
|
||||||
|
let name;
|
||||||
|
const out = await Promise.all(
|
||||||
|
topics.map(async (item) => {
|
||||||
|
const title = item.title;
|
||||||
|
const id = item.id;
|
||||||
|
const author = item.userAvatar.displayName;
|
||||||
|
const topicUrl = url.resolve(rootUrl, item.topicUrl.split('#')[0]);
|
||||||
|
name = item.topicUrl.split('/')[2];
|
||||||
|
|
||||||
|
const apiUrl = `https://www.kaggle.com/topics/${id}.json`;
|
||||||
|
const cache = await ctx.cache.get(apiUrl);
|
||||||
|
if (cache) {
|
||||||
|
return Promise.resolve(JSON.parse(cache));
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await got({
|
||||||
|
method: 'get',
|
||||||
|
url: apiUrl,
|
||||||
|
headers: {
|
||||||
|
Referer: topicUrl,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const content = response.data.comment.content;
|
||||||
|
|
||||||
|
const single = {
|
||||||
|
link: topicUrl,
|
||||||
|
title: title,
|
||||||
|
author: author,
|
||||||
|
description: content,
|
||||||
|
};
|
||||||
|
|
||||||
|
ctx.cache.set(apiUrl, JSON.stringify(single));
|
||||||
|
return Promise.resolve(single);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title: `${name} Topic-${sortText}`,
|
||||||
|
link: url.resolve(rootUrl, `c/${name}/discussion`),
|
||||||
|
item: out,
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user