mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-09 14:40:23 +08:00
feat:增加河北省退役士兵事务局公开信息 (#3089)
This commit is contained in:
@@ -51,6 +51,16 @@ pageClass: routes
|
||||
|
||||
<Route author="EsuRt" example="/gov/statecouncil/briefing" path="/gov/statecouncil/briefing"/>
|
||||
|
||||
### 河北省退役军人事务厅
|
||||
|
||||
<Route author="SunShinenny" example="/gov/veterans/hebei/sxxx" path="/gov/veterans/hebei/:type" :paramsDesc="['分类名']">
|
||||
|
||||
| 省内信息 | 厅内信息 | 市县信息 |
|
||||
| :------: | :------: | :------: |
|
||||
| ywgz | tnxx | sxxx |
|
||||
|
||||
</Route>
|
||||
|
||||
### 江苏省人民政府
|
||||
|
||||
<Route author="ocleo1" example="/gov/province/jiangsu/important-news" path="/gov/province/jiangsu/:category" :paramsDesc="['分类名']">
|
||||
|
||||
@@ -1419,6 +1419,9 @@ router.get('/gov/veterans/bnxx', require('./routes/gov/veterans/bnxx'));
|
||||
router.get('/gov/veterans/zcjd', require('./routes/gov/veterans/zcjd'));
|
||||
router.get('/gov/veterans/index', require('./routes/gov/veterans/index'));
|
||||
|
||||
// 河北省退伍士兵信息
|
||||
router.get('/gov/veterans/hebei/:type', require('./routes/gov/veterans/hebei'));
|
||||
|
||||
// Dilbert Comic Strip
|
||||
router.get('/dilbert/strip', require('./routes/dilbert/strip'));
|
||||
|
||||
|
||||
73
lib/routes/gov/veterans/hebei.js
Normal file
73
lib/routes/gov/veterans/hebei.js
Normal file
@@ -0,0 +1,73 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
async function load(link, ctx) {
|
||||
return await ctx.cache.tryGet(link, async () => {
|
||||
// 开始加载页面
|
||||
const response = await got.get(link);
|
||||
const $ = cheerio.load(response.data);
|
||||
// 获取标题
|
||||
const title = $('body > div.container.mt40 > div > div > div.m-lg.text-center > div.p-sm').text();
|
||||
// 获取正文内容
|
||||
const introduce = $('body > div.container.mt40 > div > div > div.m-lg.info-style-content').html();
|
||||
// eslint-disable-next-line no-useless-escape
|
||||
// 获取标题中的推送时间和作者等信息
|
||||
const temp = $('body > div.container.mt40 > div > div > div.m-lg.text-center > div.m-b-sm')
|
||||
.text()
|
||||
.replace(/[\r\n]/g, '');
|
||||
// 获取标题中的时间
|
||||
const dateTime = temp.substring(temp.indexOf('发布时间') + 5, temp.indexOf('信息来源')).trim() + ':00';
|
||||
const pubDate = new Date(new Date(dateTime).getTime()).toUTCString();
|
||||
// 获取标题中的作者
|
||||
const author = temp.substring(temp.indexOf('信息来源') + 5, temp.indexOf('阅读次数')).trim();
|
||||
|
||||
return {
|
||||
title: title,
|
||||
description: introduce,
|
||||
link: link,
|
||||
pubDate: pubDate,
|
||||
author: author,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const type = ctx.params.type;
|
||||
const checkType = {
|
||||
sxxx: '市县信息',
|
||||
tnxx: '厅内信息',
|
||||
ywgz: '省内信息',
|
||||
};
|
||||
const host = `http://tyjrswt.hebei.gov.cn/gk/${type}/`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: host,
|
||||
});
|
||||
const data = response.data;
|
||||
|
||||
const $ = cheerio.load(data);
|
||||
const list = $(`#${type}_list > li > a`).get();
|
||||
|
||||
const process = await Promise.all(
|
||||
list.map(async (item) => {
|
||||
let itemUrl = $(item).attr('href');
|
||||
if (itemUrl.indexOf('./') === 0) {
|
||||
itemUrl = 'http://tyjrswt.hebei.gov.cn' + itemUrl.substring(2);
|
||||
} else {
|
||||
itemUrl = 'http://tyjrswt.hebei.gov.cn' + itemUrl;
|
||||
}
|
||||
const single = {
|
||||
title: $(item).text(),
|
||||
link: itemUrl,
|
||||
guid: itemUrl,
|
||||
};
|
||||
const other = await load(String(itemUrl), ctx);
|
||||
return Promise.resolve(Object.assign({}, single, other));
|
||||
})
|
||||
);
|
||||
ctx.state.data = {
|
||||
title: `河北省退伍军人事务厅 - ${checkType[type]}`,
|
||||
link: host,
|
||||
description: `河北省退伍军人事务厅 - ${checkType[type]} 更新提示`,
|
||||
item: process,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user