From 7d4b0fce6fb06837af994f7989adeaf63ba5793e Mon Sep 17 00:00:00 2001 From: auto-bot-ty <75887908+auto-bot-ty@users.noreply.github.com> Date: Sat, 17 Jul 2021 16:50:53 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=8D=8E=E5=8D=97?= =?UTF-8?q?=E7=90=86=E5=B7=A5=E5=A4=A7=E5=AD=A6=E7=94=B5=E5=AD=90=E4=B8=8E?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E5=AD=A6=E9=99=A2=20-=20=E6=96=B0=E9=97=BB?= =?UTF-8?q?=E9=80=9F=E9=80=92=20(#7772)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: auto-bot-ty Co-authored-by: SettingDust --- docs/university.md | 12 +++- lib/router.js | 3 + .../universities/scut/seie/news_center.js | 58 +++++++++++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 lib/routes/universities/scut/seie/news_center.js diff --git a/docs/university.md b/docs/university.md index 105c090c5..6e139729a 100644 --- a/docs/university.md +++ b/docs/university.md @@ -438,7 +438,7 @@ pageClass: routes | 博士研究生 | 硕士研究生 | 同等学力攻读硕士学位 | 港澳台地区招生 | | :--------: | :--------: | :------------------: | :------------: | -| bsyjs | ssyjs | tdxlgdssxw | gatdqzs | +| bsyjs | ssyjs | tdxlgdssxw | gatdqzs | @@ -973,6 +973,14 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS +### 电子与信息学院 - 新闻速递 + + + +::: warning 注意 +由于学院官网对非大陆 IP 的访问存在限制,需自行部署。 +::: + ## 华南师范大学 ### 软件学院通知公告 @@ -1892,7 +1900,7 @@ type 列表: | 全部 | 教学信息 | 教学研究 | 实践教学 | 质量监控 | 通知公告 | | :--: | :------: | :------: | :------: | :------: | :------: | -| all | jxxx | jxyj | sjjx | zljk | tzgg | +| all | jxxx | jxyj | sjjx | zljk | tzgg | diff --git a/lib/router.js b/lib/router.js index 3bd79ed39..825af6c23 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3237,6 +3237,9 @@ router.get('/scvtc/xygg', require('./routes/universities/scvtc/xygg')); // 华南理工大学土木与交通学院 router.get('/scut/scet/notice', require('./routes/universities/scut/scet/notice')); +// 华南理工大学电子与信息学院 +router.get('/scut/seie/news_center', require('./routes/universities/scut/seie/news_center')); + // OneJAV router.get('/onejav/:type/:key?', require('./routes/onejav/one')); diff --git a/lib/routes/universities/scut/seie/news_center.js b/lib/routes/universities/scut/seie/news_center.js new file mode 100644 index 000000000..5ed2c01f1 --- /dev/null +++ b/lib/routes/universities/scut/seie/news_center.js @@ -0,0 +1,58 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const rootUrl = 'https://www2.scut.edu.cn'; + const url = `${rootUrl}/ee/16285/list.htm`; + const response = await got.get(url); + const $ = cheerio.load(response.data); + + const list = $('.news_ul li'); + const articleList = list + .map((_, item) => { + item = $(item); + const titleElement = item.find('.news_title a'); + return { + title: titleElement.attr('title'), + link: titleElement.attr('href'), + pubDate: parseDate(item.find('.news_meta').text(), 'YYYY-MM-DD'), + }; + }) + .get(); + + const items = await Promise.all( + articleList.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: `${rootUrl}${item.link}`, + }); + const content = cheerio.load(detailResponse.data, { decodeEntities: false }); + + content('.wp_articlecontent *').each((_, child) => { + const childElem = content(child); + childElem.removeAttr('style'); + childElem.removeAttr('lang'); + childElem.removeAttr('original-src'); + childElem.removeAttr('sudyfile-attr'); + childElem.removeAttr('data-layer'); + if ((!childElem.text().replace('\n', '').trim().length && !childElem.has('img')) || childElem.attr('name') === '_GoBack' || childElem.is('style')) { + childElem.remove(); + } + }); + + const contentHTML = content('.wp_articlecontent').html(); + item.description = contentHTML.replace(/^(
)+|(
)+$/g, '').trim(); + return item; + }) + ) + ); + + ctx.state.data = { + title: '华南理工大学电子与信息学院 - 新闻速递', + link: url, + item: items, + }; +};