feat: add 增加桂林航天工业学院RSS规则 (#4166)

This commit is contained in:
MlTree
2020-03-08 01:20:27 +08:00
committed by GitHub
parent c7f3fdfc27
commit 8f7c8ab29a
3 changed files with 92 additions and 0 deletions

View File

@@ -327,6 +327,20 @@ xskb1 对应 http://www.auto.uestc.edu.cn/index/xskb1.htm
</Route>
## 桂林航天工业学院
### 新闻资讯
<Route author="wyml" example="/guat/news/ghyw" path="/guat/news/:type?" :paramsDesc="['资讯类型,如下表']">
| 桂航要闻 | 院部动态 | 通知公告 | 信息公开 | 桂航大讲堂 |
| -------- | -------- | -------- | -------- | ---------- |
| gdyw | ybdt | tzgg | xxgk | ghdjt |
注 1: 不要吐槽拼音缩写,缩写原本的 URL 构成就这样。
</Route>
## 哈尔滨工程大学
### 本科生院工作通知

View File

@@ -2335,6 +2335,9 @@ router.get('/yzu/yjszs/:type', require('./routes/universities/yzu/yjszs'));
// 国家自然科学基金委员会
router.get('/nsfc/news/:type?', require('./routes/nsfc/news'));
// 桂林航天工业学院
router.get('/guat/news/:type?', require('./routes/guat/news'));
// 国家留学网
router.get('/csc/notice/:type?', require('./routes/csc/notice'));

75
lib/routes/guat/news.js Normal file
View File

@@ -0,0 +1,75 @@
/*
* @Author: Kingsr
* @Date: 2020-03-04 15:59:49
* @LastEditors: Kingsr
* @LastEditTime: 2020-03-04 17:39:01
* @Description: 桂林航天工业学院RSSHub规则
*/
const got = require('@/utils/got');
const cheerio = require('cheerio');
const host = 'https://www.guat.edu.cn';
const urls = {
ghyw: {
url: `${host}/index/ghyw.htm`,
title: '桂航要闻',
},
ybdt: {
url: `${host}/index/ybdt.htm`,
title: '院部动态',
},
tzgg: {
url: `${host}/index/tzgg.htm`,
title: '通知公告',
},
xxgk: {
url: `${host}/index/xxgk.htm`,
title: '信息公开',
},
ghdjt: {
url: `${host}/index/ghdjt.htm`,
title: '桂航大讲堂',
},
};
module.exports = async (ctx) => {
const type = ctx.params.type || 'ghyw';
if (!urls[type]) {
throw Error('参数不在可选范围之内');
}
const url = urls[type].url;
const title = urls[type].title;
const response = await got({
method: 'get',
url: url,
});
const data = response.data;
const $ = cheerio.load(data);
const list = new Array();
// 适应桂航的奇葩规则
for (let index = 0; index < 19; index++) {
const element = $(`#line_u8_${index}`);
const item_title = element
.find('a')
.first()
.text();
const item_link = element
.find('a')
.first()
.attr('href')
.replace('../', host);
list.push({
title: item_title,
description: `${title} - ${item_title}`,
link: item_link,
});
}
ctx.state.data = {
title: `桂林航天工业学院 - ${title}`,
link: 'https://www.guat.edu.cn',
item: list,
};
};