From 67eba5dfd6c78f319218ccdbadbfc72c7c85105e Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Sun, 15 Sep 2019 12:41:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E5=9B=9B=E5=B7=9D?= =?UTF-8?q?=E5=A4=A7=E5=AD=A6=E5=AD=A6=E5=B7=A5=E9=83=A8=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E5=85=AC=E5=91=8A=20(#3062)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/university.md | 4 +++ lib/router.js | 1 + lib/routes/universities/scu/xg.js | 50 +++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 lib/routes/universities/scu/xg.js diff --git a/docs/university.md b/docs/university.md index 6700eab450..f3f116cc3c 100644 --- a/docs/university.md +++ b/docs/university.md @@ -830,6 +830,10 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet +### 学工部通知公告 + + + ## 四川旅游学院 ### 信息与工程学院动态公告列表 diff --git a/lib/router.js b/lib/router.js index 6197f10b4e..e322c1fa93 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1180,6 +1180,7 @@ router.get('/babykingdom/:id/:order?', require('./routes/babykingdom')); // 四川大学 router.get('/scu/jwc/notice', require('./routes/universities/scu/jwc')); +router.get('/scu/xg/notice', require('./routes/universities/scu/xg')); // 浙江工商大学 router.get('/zjgsu/tzgg', require('./routes/universities/zjgsu/tzgg/scripts')); diff --git a/lib/routes/universities/scu/xg.js b/lib/routes/universities/scu/xg.js new file mode 100644 index 0000000000..b218e265fc --- /dev/null +++ b/lib/routes/universities/scu/xg.js @@ -0,0 +1,50 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +async function load_detail(list, cache) { + return await Promise.all( + list.map(async (item) => { + const notice_item = cheerio.load(item); + const url = 'http://xsc.scu.edu.cn' + notice_item('a').attr('href'); + return await cache.tryGet(url, async () => { + const detail_response = await got({ + method: 'get', + url: url, + headers: { + Referer: 'http://xsc.scu.edu.cn/WEBSITE/XG', + Host: 'xsc.scu.edu.cn', + }, + }); + const detail = cheerio.load(detail_response.data); + return { + title: notice_item('a').attr('title'), + description: detail('.news-content').html(), + link: url, + }; + }); + }) + ); +} + +module.exports = async (ctx) => { + const response = await got({ + method: 'get', + url: 'http://xsc.scu.edu.cn/WEBSITE/XG', + headers: { + Host: 'xsc.scu.edu.cn', + }, + }); + + const data = response.data; + + const $ = cheerio.load(data); + const list = $('.news-pannel.notice-news > .news-body > .news-list > ul > li').get(); + + const detail = await load_detail(list, ctx.cache); + + ctx.state.data = { + title: '四川大学学工部 - 通知公告', + link: 'http://xsc.scu.edu.cn/WEBSITE/XG', + item: detail, + }; +};