diff --git a/docs/university.md b/docs/university.md index 34f2ef3ed0..80b21098fe 100644 --- a/docs/university.md +++ b/docs/university.md @@ -1062,6 +1062,18 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet +## 武昌首义学院 + +### 新闻中心 + + + +| 学校要闻 | 综合新闻 | 媒体聚焦 | +| -------- | -------- | -------- | +| xxyw | zhxw | mtjj | + + + ## 武汉大学 ### 计算机学院公告 diff --git a/lib/router.js b/lib/router.js index c43ad6e75b..06f516f54b 100644 --- a/lib/router.js +++ b/lib/router.js @@ -689,6 +689,9 @@ router.get('/hust/auto/news/', require('./routes/universities/hust/aia/news')); router.get('/hust/aia/news/', require('./routes/universities/hust/aia/news')); router.get('/hust/aia/notice/:type?', require('./routes/universities/hust/aia/notice')); +// 武昌首义学院 +router.get('/wsyu/news/:type?', require('./routes/universities/wsyu/news')); + // 井冈山大学 router.get('/jgsu/jwc', require('./routes/universities/jgsu/jwc')); diff --git a/lib/routes/universities/wsyu/news.js b/lib/routes/universities/wsyu/news.js new file mode 100644 index 0000000000..56c91c05f5 --- /dev/null +++ b/lib/routes/universities/wsyu/news.js @@ -0,0 +1,85 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const url = require('url'); + +const baseUrl = 'http://www.wsyu.edu.cn'; + +const typeMap = { + xxyw: { + name: '学校要闻', + url: '/info/iList.jsp?cat_id=10307', + }, + zhxw: { + name: '综合新闻', + url: '/info/iList.jsp?cat_id=10119', + }, + mtjj: { + name: '媒体聚焦', + url: '/info/iList.jsp?cat_id=10120', + }, +}; + +module.exports = async (ctx) => { + const type = ctx.params.type || 'xxyw'; + const link = baseUrl + typeMap[type].url; + const response = await got({ + method: 'get', + url: link, + headers: { + Referer: baseUrl, + }, + }); + const $ = cheerio.load(response.data); + + const urlList = $('.mainContent li') + .slice(0, 10) + .map((i, e) => $('a', e).attr('href')) + .get(); + + const titleList = $('.mainContent li') + .slice(0, 10) + .map((i, e) => $('a', e).text()) + .get(); + + const dateList = $('.mainContent li') + .slice(0, 10) + .map((i, e) => $('span', e).text()) + .get(); + + const out = await Promise.all( + urlList.map(async (itemUrl, index) => { + itemUrl = url.resolve(baseUrl, itemUrl); + if (itemUrl.indexOf('.htm') !== -1) { + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + const response = await got.get(itemUrl); + const $ = cheerio.load(response.data); + $('.content .photos').remove(); + const single = { + title: titleList[index], + link: itemUrl, + description: $('.content').html(), + pubDate: dateList[index], + }; + ctx.cache.set(itemUrl, JSON.stringify(single)); + return Promise.resolve(single); + } else { + const single = { + title: titleList[index], + link: itemUrl, + description: '此链接为文件,请点击下载', + pubDate: dateList[index], + }; + return Promise.resolve(single); + } + }) + ); + + ctx.state.data = { + title: '武昌首义学院-' + typeMap[type].name, + link: link, + item: out, + }; +};