diff --git a/docs/university.md b/docs/university.md index 875e4e3e55..34f2ef3ed0 100644 --- a/docs/university.md +++ b/docs/university.md @@ -327,6 +327,20 @@ xskb1 对应 http://www.auto.uestc.edu.cn/index/xskb1.htm +## 桂林航天工业学院 + +### 新闻资讯 + + + +| 桂航要闻 | 院部动态 | 通知公告 | 信息公开 | 桂航大讲堂 | +| -------- | -------- | -------- | -------- | ---------- | +| gdyw | ybdt | tzgg | xxgk | ghdjt | + +注 1: 不要吐槽拼音缩写,缩写原本的 URL 构成就这样。 + + + ## 哈尔滨工程大学 ### 本科生院工作通知 diff --git a/lib/router.js b/lib/router.js index c21c916a70..19367e0e22 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/guat/news.js b/lib/routes/guat/news.js new file mode 100644 index 0000000000..62758a15a8 --- /dev/null +++ b/lib/routes/guat/news.js @@ -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, + }; +};