From 8f7c8ab29a751b6dd1a44e9cf27fe18486aed69f Mon Sep 17 00:00:00 2001 From: MlTree <30387152+wyml@users.noreply.github.com> Date: Sun, 8 Mar 2020 01:20:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E5=A2=9E=E5=8A=A0=E6=A1=82?= =?UTF-8?q?=E6=9E=97=E8=88=AA=E5=A4=A9=E5=B7=A5=E4=B8=9A=E5=AD=A6=E9=99=A2?= =?UTF-8?q?RSS=E8=A7=84=E5=88=99=20(#4166)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/university.md | 14 ++++++++ lib/router.js | 3 ++ lib/routes/guat/news.js | 75 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 lib/routes/guat/news.js 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, + }; +};