diff --git a/docs/university.md b/docs/university.md index c217d1955b..f378f22385 100644 --- a/docs/university.md +++ b/docs/university.md @@ -923,6 +923,10 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet +### 新闻网讲座预告 + + + ## 重庆科技学院 ### 教务处公告 diff --git a/lib/router.js b/lib/router.js index af7ea5fc11..62b0391e9f 100644 --- a/lib/router.js +++ b/lib/router.js @@ -590,6 +590,7 @@ router.get('/heu/ugs/news/:author?/:category?', require('./routes/universities/h // 重庆大学 router.get('/cqu/jwc/announcement', require('./routes/universities/cqu/jwc/announcement')); +router.get('/cqu/news/jzyg', require('./routes/universities/cqu/news/jzyg')); // 南京信息工程大学 router.get('/nuist/bulletin/:category?', require('./routes/universities/nuist/bulletin')); diff --git a/lib/routes/universities/cqu/news/jzyg.js b/lib/routes/universities/cqu/news/jzyg.js new file mode 100644 index 0000000000..c9a5bd8d52 --- /dev/null +++ b/lib/routes/universities/cqu/news/jzyg.js @@ -0,0 +1,23 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const util = require('./utils'); + +module.exports = async (ctx) => { + const response = await got({ + method: 'get', + url: 'http://news.cqu.edu.cn/newsv2/info-24.html', + }); + + const data = response.data; + const $ = cheerio.load(data); + const list = $('.item').get(); + + const result = await util.ProcessFeed(list, ctx.cache); + + ctx.state.data = { + title: '重庆大学新闻网-讲座预告', + link: 'http://news.cqu.edu.cn/newsv2/info-24.html', + description: '重庆大学新闻网-讲座预告', + item: result, + }; +}; diff --git a/lib/routes/universities/cqu/news/utils.js b/lib/routes/universities/cqu/news/utils.js new file mode 100644 index 0000000000..c7083b9768 --- /dev/null +++ b/lib/routes/universities/cqu/news/utils.js @@ -0,0 +1,48 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +// 加载文章页 +async function load(link) { + const response = await got.get(link); + const $ = cheerio.load(response.data); + + // 提取内容 + const description = $('.dinfo').html() + $('.acontent').html(); + + return { description }; +} + +const ProcessFeed = async (list, caches) => + await Promise.all( + list.map(async (item) => { + const $ = cheerio.load(item); + + const $title1 = $('.title a').eq(0); + const $title2 = $('.title a').eq(1); + let itemUrl = $title2.attr('href'); + let title = $title1.text() + ' - ' + $title2.text(); + + if (typeof itemUrl === 'undefined') { + itemUrl = $title1.attr('href'); + title = $title1.text(); + } + + // 列表上提取到的信息 + const single = { + title: title, + link: itemUrl, + guid: itemUrl, + }; + + // 使用tryGet方法从缓存获取内容。 + // 当缓存中无法获取到链接内容的时候,则使用load方法加载文章内容。 + const other = await caches.tryGet(itemUrl, async () => await load(itemUrl)); + + // 合并解析后的结果集作为该篇文章最终的输出结果 + return Promise.resolve(Object.assign({}, single, other)); + }) + ); + +module.exports = { + ProcessFeed, +};