diff --git a/docs/university.md b/docs/university.md index e38004ef6d..4580944845 100644 --- a/docs/university.md +++ b/docs/university.md @@ -478,13 +478,13 @@ xskb1 对应 ## 福州大学 -### 教务处教学通知 +### 教务处通知 - + -### 教务处专家讲座 - - +| 教学通知 | 专家讲座 | +| -------- | -------- | +| jxtz | zjjz | ## 广东工业大学 diff --git a/lib/router.js b/lib/router.js index 1ff7ce53cd..acd99937b0 100644 --- a/lib/router.js +++ b/lib/router.js @@ -905,8 +905,7 @@ router.get('/usst/jwc', require('./routes/universities/usst/jwc')); router.get('/lyu/news/:type', require('./routes/universities/lyu/news/index')); // 福州大学 -router.get('/fzu/jxtz', require('./routes/universities/fzu/jxtz')); -router.get('/fzu/zjjz', require('./routes/universities/fzu/zjjz')); +router.get('/fzu/:type', require('./routes/universities/fzu/news')); // ifanr router.get('/ifanr/:channel?', require('./routes/ifanr/index')); diff --git a/lib/routes/universities/fzu/jxtz.js b/lib/routes/universities/fzu/jxtz.js deleted file mode 100644 index 6aa8c3b563..0000000000 --- a/lib/routes/universities/fzu/jxtz.js +++ /dev/null @@ -1,23 +0,0 @@ -const got = require('@/utils/got'); -module.exports = async (ctx) => { - const response = await got({ - method: 'get', - url: `http://jwch.fzu.edu.cn/plus/json.aspx?jid=J131925584886784703&classid=1804&page=1&column=infoid%2Cclassid%2Ctitle%2Cdefaultpic%2Cintro%2Cadddate%2Curl%2Cclassname`, - headers: { - Referer: `http://jwch.fzu.edu.cn/jxtz/`, - }, - }); - const data = response.data.data; - - ctx.state.data = { - title: `福州大学教务处教学通知`, - link: `http://jwch.fzu.edu.cn/jxtz/`, - description: `福州大学教务处教学通知`, - item: data.map((item) => ({ - title: item.title, - description: `${item.title}`, - pubDate: `${item.adddate}`, - link: `${item.url}`, - })), - }; -}; diff --git a/lib/routes/universities/fzu/news.js b/lib/routes/universities/fzu/news.js new file mode 100644 index 0000000000..64cf9fa265 --- /dev/null +++ b/lib/routes/universities/fzu/news.js @@ -0,0 +1,65 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const url_map = { + jxtz: '1804', + zjjz: '1809', +}; +const Referer_map = { + jxtz: '/jxtz/', + zjjz: '/zjjz/', +}; +const title_map = { + jxtz: '教学通知', + zjjz: '专家讲座', +}; +const description_map = { + jxtz: '教学通知', + zjjz: '嘉锡讲坛/信息素养讲座通知', +}; + +module.exports = async (ctx) => { + const type = ctx.params.type || ''; + const response = await got({ + method: 'get', + url: `http://jwch.fzu.edu.cn/plus/json.aspx?jid=J131925584886784703&classid=${url_map[type]}&page=1&column=infoid%2Cclassid%2Ctitle%2Cdefaultpic%2Cintro%2Cadddate%2Curl%2Cclassname`, + headers: { + Referer: `http://jwch.fzu.edu.cn${Referer_map[type]}`, + }, + }); + const data = response.data.data; + + const urls = new Array(); + for (let i = 0; i <= 9; i++) { + urls[i] = data[i].url; + } + + const items = await Promise.all( + urls.map( + async (item) => + await ctx.cache.tryGet(item, async () => { + const response = await got({ + method: 'get', + url: item, + }); + const $ = cheerio.load(response.data); + const title = $('title').html(); + const description = $('.articelMain').html(); + const pubDate = $('.xl_sj_icon').text().replace('发布时间:', ''); + return { + title, + link: item, + description, + pubDate, + }; + }) + ) + ); + + ctx.state.data = { + title: `福州大学教务处${title_map[type]}`, + link: `http://jwch.fzu.edu.cn/jxtz/`, + description: `福州大学教务处${description_map[type]}`, + item: items, + }; +}; diff --git a/lib/routes/universities/fzu/zjjz.js b/lib/routes/universities/fzu/zjjz.js deleted file mode 100644 index d61f14bb70..0000000000 --- a/lib/routes/universities/fzu/zjjz.js +++ /dev/null @@ -1,23 +0,0 @@ -const got = require('@/utils/got'); -module.exports = async (ctx) => { - const response = await got({ - method: 'get', - url: `http://jwch.fzu.edu.cn/plus/json.aspx?jid=J131925584886784703&classid=1809&page=1&column=infoid%2Cclassid%2Ctitle%2Cdefaultpic%2Cintro%2Cadddate%2Curl%2Cclassname`, - headers: { - Referer: `http://jwch.fzu.edu.cn/zjjz/`, - }, - }); - const data = response.data.data; - - ctx.state.data = { - title: `福州大学教务处专家讲座`, - link: `http://jwch.fzu.edu.cn/zjjz/`, - description: `福州大学教务处加锡讲坛/信息素养讲座通知`, - item: data.map((item) => ({ - title: item.title, - description: `${item.title}`, - pubDate: `${item.adddate}`, - link: `${item.url}`, - })), - }; -};