From 2af86de724a86e15689303fe6e65355531fe78bb Mon Sep 17 00:00:00 2001 From: yikZero <52102693+yikZero@users.noreply.github.com> Date: Wed, 5 Aug 2020 17:24:29 -0500 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=B5=99=E6=B1=9F?= =?UTF-8?q?=E5=B7=A5=E4=B8=9A=E5=A4=A7=E5=AD=A6=E8=AE=BE=E8=AE=A1=E4=B8=8E?= =?UTF-8?q?=E5=BB=BA=E7=AD=91=E5=AD=A6=E9=99=A2=E9=80=9A=E7=9F=A5=20(#5348?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/university.md | 10 +++++ lib/router.js | 1 + lib/routes/universities/zjut/design.js | 59 ++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 lib/routes/universities/zjut/design.js diff --git a/docs/university.md b/docs/university.md index 4a0354a7b..8a295bbac 100644 --- a/docs/university.md +++ b/docs/university.md @@ -1727,6 +1727,16 @@ type 列表: +### 设计与建筑学院 + + + +| 学术科研 | 学院新闻 | 公告通知 | 学术交流 | +| ------ | -------- | -------- | -------- | +| 5 | 16 | 18 | 20 | + + + ## 郑州大学 ### 郑州大学新闻网 diff --git a/lib/router.js b/lib/router.js index bf919c29f..6523021ad 100644 --- a/lib/router.js +++ b/lib/router.js @@ -796,6 +796,7 @@ router.get('/buaa/news/:type', require('./routes/universities/buaa/news/index')) // 浙江工业大学 router.get('/zjut/:type', require('./routes/universities/zjut/index')); +router.get('/zjut/design/:type', require('./routes/universities/zjut/design')); // 上海大学 router.get('/shu/jwc/:type?', require('./routes/universities/shu/jwc')); diff --git a/lib/routes/universities/zjut/design.js b/lib/routes/universities/zjut/design.js new file mode 100644 index 000000000..416f7984a --- /dev/null +++ b/lib/routes/universities/zjut/design.js @@ -0,0 +1,59 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); +const host = 'http://www.design.zjut.edu.cn'; + +module.exports = async (ctx) => { + const bigClassId = ctx.params.type; + const url = host + '/BigClass.jsp?bigclassid=' + bigClassId; + + const response = await got({ method: 'get', url: url, responseType: 'buffer' }); + response.data = iconv.decode(response.data, 'gbk'); + const $ = cheerio.load(response.data); + + const htmlTitle = $("span[class='title1']").text().replace('\n', '').trim(); + + const list = $("td[class='newstd']") + .map((i, e) => { + const element = $(e); + const title = element.find('a').text(); + let link = element.find('a').attr('href'); + if (!link.startsWith('http')) { + link = host + '/' + link; + } + const date = element.find("span[class='datetime']").text().replace('[', '').replace(']', ''); + + return { + title: title, + description: '', + link: link, + pubDate: new Date(date).toUTCString(), + }; + }) + .get() + .slice(0, 20); + + const result = await Promise.all( + list.map(async (item) => { + const link = item.link; + + const cache = await ctx.cache.get(link); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const itemReponse = await got({ method: 'get', url: link, responseType: 'buffer' }); + const itemElement = cheerio.load(iconv.decode(itemReponse.data, 'gbk')); + item.description = itemElement('#jiacu').html(); + + ctx.cache.set(link, JSON.stringify(item)); + return Promise.resolve(item); + }) + ); + + ctx.state.data = { + title: '浙江工业大学设计与建筑学院 - ' + htmlTitle, + link: url, + item: result, + }; +};