mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-08 22:19:40 +08:00
feat: add 中华人民共和国教育部
This commit is contained in:
@@ -342,6 +342,18 @@ pageClass: routes
|
||||
|
||||
</Route>
|
||||
|
||||
## 中华人民共和国教育部
|
||||
|
||||
### 新闻
|
||||
|
||||
<Route author="Crawler995" example="/gov/moe/policy_anal" path="/gov/moe/:type" :paramsDesc="['分类名']">
|
||||
|
||||
| 政策解读 | 最新文件 | 公告公示 | 教育部简报 |
|
||||
| :---------: | :---------: | :------: | :---------------: |
|
||||
| policy_anal | newest_file | notice | edu_ministry_news |
|
||||
|
||||
</Route>
|
||||
|
||||
## 中华人民共和国外交部
|
||||
|
||||
### 发言人表态
|
||||
|
||||
@@ -1119,6 +1119,9 @@ router.get('/gov/customs/list/:gchannel', require('./routes/gov/customs/list'));
|
||||
// 中华人民共和国生态环境部
|
||||
router.get('/gov/mee/gs', require('./routes/gov/mee/gs'));
|
||||
|
||||
// 中华人民共和国教育部
|
||||
router.get('/gov/moe/:type', require('./routes/gov/moe/moe'));
|
||||
|
||||
// 中华人民共和国外交部
|
||||
router.get('/gov/fmprc/fyrbt', require('./routes/gov/fmprc/fyrbt'));
|
||||
|
||||
|
||||
84
lib/routes/gov/moe/moe.js
Normal file
84
lib/routes/gov/moe/moe.js
Normal file
@@ -0,0 +1,84 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const logger = require('@/utils/logger');
|
||||
const liburl = require('url');
|
||||
|
||||
const moeUrl = 'http://www.moe.gov.cn/';
|
||||
const typesIdMap = [
|
||||
{ type: 'policy_anal', id: 'tt_con2', name: '政策解读' },
|
||||
{ type: 'newest_file', id: 'nine_con1', name: '最新文件' },
|
||||
{ type: 'notice', id: 'nine_con2', name: '公告公示' },
|
||||
{ type: 'edu_ministry_news', id: 'nine_con3', name: '教育部简报' },
|
||||
];
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const type = ctx.params.type;
|
||||
let id = '';
|
||||
let name = '';
|
||||
|
||||
for (let i = 0; i < typesIdMap.length; i++) {
|
||||
if (typesIdMap[i].type === type) {
|
||||
id = typesIdMap[i].id;
|
||||
name = typesIdMap[i].name;
|
||||
}
|
||||
}
|
||||
|
||||
if (id === '') {
|
||||
logger.error('The given type not found.');
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: moeUrl,
|
||||
Host: 'www.moe.gov.cn',
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
const newsLis = $('div#' + id + '>ul>li');
|
||||
|
||||
ctx.state.data = {
|
||||
title: name,
|
||||
link: moeUrl,
|
||||
item: await Promise.all(
|
||||
newsLis
|
||||
.map(async (_, item) => {
|
||||
item = $(item);
|
||||
|
||||
const firstA = item.find('a');
|
||||
const itemUrl = liburl.resolve(moeUrl, firstA.attr('href'));
|
||||
|
||||
const infos = await ctx.cache.tryGet(itemUrl, async () => {
|
||||
const res = {};
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: itemUrl,
|
||||
Host: 'www.moe.gov.cn',
|
||||
});
|
||||
const data = cheerio.load(response.data);
|
||||
|
||||
if (itemUrl.indexOf('www.gov.cn') > -1) {
|
||||
res.description = data('div.pages_content > p').html();
|
||||
res.title = data('div.article > h1').text();
|
||||
} else if (itemUrl.indexOf('srcsite') > -1) {
|
||||
res.description = data('div#xxgk_content_div').html();
|
||||
res.title = data('div#xxgk_content_redheadbg > h1').text();
|
||||
} else if (itemUrl.indexOf('jyb_') > -1) {
|
||||
res.description = data('div.TRS_Editor').html();
|
||||
res.title = data('div#content_body > h1').text();
|
||||
}
|
||||
|
||||
return res;
|
||||
});
|
||||
|
||||
return {
|
||||
title: infos.title,
|
||||
description: infos.description,
|
||||
link: itemUrl,
|
||||
pubDate: `${new Date().getFullYear()}-${item.find('span').text()}`,
|
||||
};
|
||||
})
|
||||
.get()
|
||||
),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user