From fee2f2fdddf54e732b5d9c8d00a5f7df06c4785c Mon Sep 17 00:00:00 2001 From: junbaor Date: Mon, 13 Apr 2020 19:28:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=B5=99=E6=B1=9F?= =?UTF-8?q?=E5=B7=A5=E4=B8=9A=E5=A4=A7=E5=AD=A6=E5=8A=A8=E6=80=81=20(#4385?= =?UTF-8?q?)=20(#4394)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/university.md | 12 ++++++ lib/router.js | 3 ++ lib/routes/universities/zjut/index.js | 59 +++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 lib/routes/universities/zjut/index.js diff --git a/docs/university.md b/docs/university.md index 6f240cd287..0dba433c1c 100644 --- a/docs/university.md +++ b/docs/university.md @@ -1446,6 +1446,18 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet +## 浙江工业大学 + +### 浙江工业大学 + + + +| 公告栏 | 每周会议 | 屏峰班车 | 新闻速递 | 学术动态 | +| ------ | -------- | -------- | -------- | -------- | +| 1 | 2 | 3 | 10 | 25 | + + + ## 郑州大学 ### 郑州大学新闻网 diff --git a/lib/router.js b/lib/router.js index b8468ba673..6a015abf93 100644 --- a/lib/router.js +++ b/lib/router.js @@ -740,6 +740,9 @@ router.get('/nku/jwc/:type?', require('./routes/universities/nku/jwc/index')); // 北京航空航天大学 router.get('/buaa/news/:type', require('./routes/universities/buaa/news/index')); +// 浙江工业大学 +router.get('/zjut/:type', require('./routes/universities/zjut/index')); + // 上海大学 router.get('/shu/jwc/:type?', require('./routes/universities/shu/jwc')); diff --git a/lib/routes/universities/zjut/index.js b/lib/routes/universities/zjut/index.js new file mode 100644 index 0000000000..be5da4f315 --- /dev/null +++ b/lib/routes/universities/zjut/index.js @@ -0,0 +1,59 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); +const host = 'http://www.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='lefttitle1']").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(); + + 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, + }; +};