diff --git a/docs/README.md b/docs/README.md index 114a6d2b8d..d46753338c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2108,6 +2108,16 @@ category 列表: 工作通知:无 +### 重庆大学 + +#### 教务网通知公告 + +举例: + +路由: `/cqu/jwc/announcement` + +参数: 无 + ### 成都信息工程大学 #### 成信新闻网 diff --git a/router.js b/router.js index 3a993f17d9..8abb909bb1 100644 --- a/router.js +++ b/router.js @@ -506,6 +506,9 @@ router.get('/nchu/jwc/:type?', require('./routes/universities/nchu/jwc')); // 哈尔滨工程大学 router.get('/heu/ugs/news/:author?/:category?', require('./routes/universities/heu/ugs/news')); +// 重庆大学 +router.get('/cqu/jwc/announcement', require('./routes/universities/cqu/jwc/announcement')); + // 成都信息工程大学 router.get('/cuit/cxxww/:type?', require('./routes/universities/cuit/cxxww')); diff --git a/routes/universities/cqu/jwc/announcement.js b/routes/universities/cqu/jwc/announcement.js new file mode 100644 index 0000000000..24e3eda101 --- /dev/null +++ b/routes/universities/cqu/jwc/announcement.js @@ -0,0 +1,60 @@ +const axios = require('../../../../utils/axios'); +const cheerio = require('cheerio'); + +const baseUrl = 'http://jwc.cqu.edu.cn'; +const cacheTime = 24 * 60 * 60; + +module.exports = async (ctx) => { + const response = await axios({ + method: 'get', + url: 'http://jwc.cqu.edu.cn/announcement', + headers: { + Referer: 'http://jwc.cqu.edu.cn/', + }, + }); + + const data = response.data; + const $ = cheerio.load(data); + const links = $('.views-row a') + .slice(0, 5) + .map((index, item) => { + item = $(item); + return { + title: item.text(), + link: baseUrl + item.attr('href'), + }; + }) + .get(); + + const items = await Promise.all( + [...links].map(async ({ title, link }) => { + const item = { + title: title, + link: link, + }; + const cache = await ctx.cache.get(link); + if (cache) { + return JSON.parse(cache); + } + const response = await axios({ + method: 'get', + url: link, + }); + const $ = cheerio.load(response.data); + item.author = $('.username').text(); + item.pubDate = $('time').attr('datetime'); + item.description = + $('div .field-items').html() && + $('div .field-items') + .find('p') + .text(); + await ctx.cache.set(item.link, JSON.stringify(item), cacheTime); + return Promise.resolve(item); + }) + ); + ctx.state.data = { + title: '重庆大学教务处通知公告', + link: 'http://jwc.cqu.edu.cn/announcement', + item: items.filter((x) => x), + }; +};