feat(route): add chsi/hotnews (#12154)

* feat(route): add chsi/hotnews

* feat(route): add chsi/hotnews

* add pubDate , not need timezone

* add pubDate , not need timezone

* add pubDate if $('.news-time').text()

---------

Co-authored-by: 牛鑫语 <niuxinyu@szbit.cn>
This commit is contained in:
niuyi 2023-03-22 20:40:33 +08:00 committed by GitHub
parent 8e3a4ac7a8
commit 0ccc130886
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 81 additions and 13 deletions

View File

@ -61,12 +61,12 @@ path="/ctfhub/search/:limit?/:form?/:class?/:title?"
| `:class` | 类型 |
| :------: | --------------------------------- |
| 0 | Jeopardy [解题] |
| 1 | Attack with Defense [AwD 攻防] |
| 2 | Robo Hacking Game [RHG AI 自动化] |
| 3 | Real World [RW 真实世界] |
| 4 | King of The Hill [KoH 抢占山头] |
| 5 | Mix [混合] |
| 0 | Jeopardy [解题] |
| 1 | Attack with Defense [AwD 攻防] |
| 2 | Robo Hacking Game [RHG AI 自动化] |
| 3 | Real World [RW 真实世界] |
| 4 | King of The Hill [KoH 抢占山头] |
| 5 | Mix [混合] |
> class 以 <https://api.ctfhub.com/User_API/Event/getType> 的返回结果为准
@ -128,8 +128,8 @@ path="/ctfhub/upcoming/:limit?"
<Route author="nczitzk" example="/mind42/tag/online" path="/mind42/tag/:id" :paramsDesc="['标签,见下表']">
| in | online | cleaning | buy | best | services | for | carpet | service | india | company | and | de | mapa | control | malware | online-dating-website-reviews | virus | international-online-dating-sites-review | repair |
| -- | ------ | -------- | --- | ---- | -------- | --- | ------ | ------- | ----- | ------- | --- | -- | ---- | ------- | ------- | ----------------------------- | ----- | ---------------------------------------- | ------ |
| in | online | cleaning | buy | best | services | for | carpet | service | india | company | and | de | mapa | control | malware | online-dating-website-reviews | virus | international-online-dating-sites-review | repair |
| --- | ------ | -------- | --- | ---- | -------- | --- | ------ | ------- | ----- | ------- | --- | --- | ---- | ------- | ------- | ----------------------------- | ----- | ---------------------------------------- | ------ |
</Route>
@ -274,9 +274,9 @@ path="/ctfhub/upcoming/:limit?"
<Route author="zytomorrow" example="/dykszx/news" path="/dykszx/news/:type?" :paramsDesc="['考试类型']">
| 新闻中心 | 公务员考试 | 事业单位 | (职)业资格、职称考试 | 其他 |
| 新闻中心 | 公务员考试 | 事业单位 | (职)业资格、职称考试 | 其他 |
| :------: | :--------: | :------: | :--------------------: | :---: |
| all | gwy | sydw | zyzc | other |
| all | gwy | sydw | zyzc | other |
</Route>
@ -564,9 +564,9 @@ path="/ctfhub/upcoming/:limit?"
:::
| 每周收藏排行榜・TOP5 | 每周热门「读书笔记」榜 TOP5 | 【印象话题】选择的悖论 | 【印象专题】如何一秒洞察问题本质? | 「识堂开讲」5 位嘉宾精华笔记大放送 | 【印象话题】培养专注力的 5 个步骤 | 🎁购物清单主题活动获奖结果 |
| -------------------- | --------------------------- | ---------------------- | ---------------------------------- | ---------------------------------- | --------------------------------- | -------------------------- |
| 32 | 33 | 101 | 103 | 104 | 105 | 106 |
| 每周收藏排行榜・TOP5 | 每周热门「读书笔记」榜 TOP5 | 【印象话题】选择的悖论 | 【印象专题】如何一秒洞察问题本质? | 「识堂开讲」5 位嘉宾精华笔记大放送 | 【印象话题】培养专注力的 5 个步骤 | 🎁 购物清单主题活动获奖结果 |
| -------------------- | --------------------------- | ---------------------- | ---------------------------------- | ---------------------------------- | --------------------------------- | --------------------------- |
| 32 | 33 | 101 | 103 | 104 | 105 | 106 |
</Route>
@ -703,6 +703,10 @@ path="/ctfhub/upcoming/:limit?"
<Route author="SunBK201" example="/chsi/kydt" path="/chsi/kydt" radar="1" />
### 考研热点新闻
<Route author="yanbot-team" example="/chsi/hotnews" path="/chsi/hotnews" radar="1" />
## 中国智库网
### 观点与实践

56
lib/v2/chsi/hotnews.js Normal file
View File

@ -0,0 +1,56 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const host = 'https://yz.chsi.com.cn';
module.exports = async (ctx) => {
const response = await got(host);
const $ = cheerio.load(response.data);
const list = $('.focus-part .index-hot a');
const items = await Promise.all(
list.map((i, item) => {
const { href: path, title: itemTitle } = item.attribs;
let itemUrl = '';
if (path.startsWith('http')) {
itemUrl = path;
} else {
itemUrl = host + path;
}
return ctx.cache.tryGet(itemUrl, async () => {
let description = '';
let itemDate = undefined;
if (path) {
const result = await got(itemUrl);
const $ = cheerio.load(result.data);
if ($('#article_dnull').html()) {
description = $('#article_dnull').html().trim();
} else {
description = itemTitle;
}
if ($('.news-time').text()) {
itemDate = $('.news-time').text();
}
} else {
description = itemTitle;
}
const result = {
title: itemTitle,
link: itemUrl,
description,
};
if (itemDate) {
result.pubDate = parseDate(itemDate, 'YYYY年MM月DD日');
}
return result;
});
})
);
ctx.state.data = {
title: `中国研究生招生信息网 - 热点`,
link: host,
description: '中国研究生招生信息网 - 热点',
item: items,
};
};

View File

@ -1,3 +1,4 @@
module.exports = {
'/hotnews': ['yanbot-team'],
'/kydt': ['SunBK201'],
};

View File

@ -8,6 +8,12 @@ module.exports = {
source: ['/kyzx/kydt'],
target: '/chsi/kydt',
},
{
title: '考研热点新闻',
docs: 'https://docs.rsshub.app/study.html#zhong-guo-yan-jiu-sheng-zhao-sheng-xin-xi-wang',
source: ['/'],
target: '/chsi/hotnews',
},
],
},
};

View File

@ -1,3 +1,4 @@
module.exports = (router) => {
router.get('/hotnews', require('./hotnews'));
router.get('/kydt', require('./kydt'));
};