From 88514fa25917ca760915e82b18825119c8cca8d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=92=8B=E6=99=A8=E8=BE=89?= <30290347+jch12138@users.noreply.github.com> Date: Fri, 3 Sep 2021 17:28:33 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=8E=A6=E9=97=A8?= =?UTF-8?q?=E5=A4=A7=E5=AD=A6=E8=88=AA=E9=99=A2=20(#8137)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 厦门大学航院 * Simplify the code * Fix the problem of tryGet --- docs/university.md | 13 ++++++ lib/router.js | 3 ++ lib/routes/universities/xmu/aero.js | 63 +++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 lib/routes/universities/xmu/aero.js diff --git a/docs/university.md b/docs/university.md index 15fd874904..17154c7418 100644 --- a/docs/university.md +++ b/docs/university.md @@ -653,6 +653,19 @@ xskb1 对应 | -------- | -------- | | jxtz | zjjz | + + +## 厦门大学 + +## 航空航天学院 + + +| 通知公告 | 本科生教务 | 研究生教务 | +| :--------: | :--------: | :--------: | +| tzgg | bksjw | yjsjw| + + + ## 复旦大学继续教育学院 ### 成人夜大通知公告 diff --git a/lib/router.js b/lib/router.js index a87a5989eb..17662a7885 100644 --- a/lib/router.js +++ b/lib/router.js @@ -945,6 +945,9 @@ router.get('/lyu/news/:type', lazyloadRouteHandler('./routes/universities/lyu/ne // 福州大学 router.get('/fzu/:type', lazyloadRouteHandler('./routes/universities/fzu/news')); +// 厦门大学 +router.get('/xmu/aero/:type', lazyloadRouteHandler('./routes/universities/xmu/aero')); + // ifanr router.get('/ifanr/:channel?', lazyloadRouteHandler('./routes/ifanr/index')); diff --git a/lib/routes/universities/xmu/aero.js b/lib/routes/universities/xmu/aero.js new file mode 100644 index 0000000000..d9eb2b87be --- /dev/null +++ b/lib/routes/universities/xmu/aero.js @@ -0,0 +1,63 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +const host = 'https://aerospace.xmu.edu.cn'; + +const urlMap = { + tzgg: '/xydt/tzgg.htm', + bksjw: '/jwxx/bksjw.htm', + yjsjw: '/jwxx/yjsjw.htm' +}; + +const titleMap = { + tzgg: '通知公告', + bksjw: '本科生教务', + yjsjw: '研究生教务' +}; + +module.exports = async (ctx) => { + const type = ctx.params.type || ''; + const response = await got({ + method: 'get', + url: host + urlMap[type], + }); + const data = response.data; + + const $ = cheerio.load(data, { decodeEntities: false }); + + const list = $('body > div.centers > div.other_right > ul > li') + .map((index, item) => { + item = $(item); + const $a = item.find('a'); + return { + title: $a.attr('title'), + link: host + $a.attr('href').slice(2,) + }; + }) + .get(); + + const result = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data, { decodeEntities: false }); + + item.description = content('#vsb_content > div').html(); + + const date = content('body > div.centers > div.other_right > form > div > div.news-info.clearfix > span:nth-child(2)').text(); + item.pubDate = parseDate(date, '发布时间:YYYY年MM月DD日'); + + return item; + }) + ) + ); + ctx.state.data = { + title: titleMap[type], + link: host, + item: result, + }; +};