diff --git a/docs/university.md b/docs/university.md index 1c4625f7b..c71932b09 100644 --- a/docs/university.md +++ b/docs/university.md @@ -1432,6 +1432,18 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet +## 中北大学 + +### 各种新闻通知 + + + +| 中北新闻 | 通知公告 | 学术活动 | 教务通知 | +| -------- | -------- | -------- | -------- | +| zbxw | tzgg | xshd | jwtz | + + + ## 中国传媒大学 ### 中国传媒大学研究生招生网 diff --git a/lib/router.js b/lib/router.js index c54f7dfad..69ac133b6 100644 --- a/lib/router.js +++ b/lib/router.js @@ -753,6 +753,9 @@ router.get('/upc/jsj/:type?', require('./routes/universities/upc/jsj')); // 华北水利水电大学 router.get('/ncwu/notice', require('./routes/universities/ncwu/notice')); +// 中北大学 +router.get('/nuc/:type', require('./routes/universities/nuc/index')); + // ifanr router.get('/ifanr/:channel?', require('./routes/ifanr/index')); diff --git a/lib/routes/universities/nuc/index.js b/lib/routes/universities/nuc/index.js new file mode 100644 index 000000000..571276481 --- /dev/null +++ b/lib/routes/universities/nuc/index.js @@ -0,0 +1,91 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const types = { + zbxw: { + name: '中北新闻', + url: 'http://www.nuc.edu.cn/index/zbxw.htm', + }, + tzgg: { + name: '通知公告', + url: 'http://www.nuc.edu.cn/index/tzgg.htm', + }, + xshd: { + name: '学术活动', + url: 'http://www.nuc.edu.cn/index/xshd.htm', + }, + jwtz: { + name: '教务通知', + url: 'http://jwc.nuc.edu.cn/index/jwtz.htm', + }, +}; +const config = { + jwtz: { + selector: { + list: '.winstyle54561 > tbody > tr > td > a', + title: 'body > center > table:nth-child(2) > tbody > tr > td.bk > table > tbody > tr:nth-child(2) > td > form > div > p:nth-child(1) > span', + date: 'body > center > table:nth-child(2) > tbody > tr > td.bk > table > tbody > tr:nth-child(2) > td > form > div > div:nth-child(2) > span.c205277_date', + content: '#vsb_content', + }, + basePath: 'http://jwc.nuc.edu.cn/', + }, + other: { + selector: { + list: 'body > div.list > div.list_con > div.list_con_rightlist > ul > li', + title: 'body > div.list > div.list_con > form > div > h2', + date: 'body > div.list > div.list_con > form > div > div:nth-child(4)', + content: 'body > div.list > div.list_con > form > div > div:nth-child(6)', + }, + basePath: 'http://www.nuc.edu.cn/', + }, +}; +module.exports = async (ctx) => { + const type = ctx.params.type || 'zbxw'; + const typeConfig = config[type] || config.other; + const response = await got({ + method: 'get', + url: `${typeConfig.basePath}index/${type}.htm`, + }); + const $ = cheerio.load(response.data); + const list = $(typeConfig.selector.list).get(); + const out = await Promise.all( + list.map(async (item) => { + const liItem = cheerio.load(item); + const aTag = liItem('a'); + const articleUrl = aTag.attr('href').replace(/\.\./, typeConfig.basePath); + const cache = await ctx.cache.get(articleUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + const response = await got({ + method: 'get', + url: articleUrl, + }); + const $ = cheerio.load(response.data); + const title = $(typeConfig.selector.title).text(); + const dateText = $(typeConfig.selector.date) + .text() + .split('    ')[0] + .replace(/时间:/, '') + .replace(/[年月日]/g, '/') + .trim(); + let content = $(typeConfig.selector.content).html(); + content = content.replace(/\/__local/g, 'http://www.nuc.edu.cn/__local'); + const data = { + title: title, + link: articleUrl, + // author: author, + description: content, + pubDate: new Date(dateText), + }; + ctx.cache.set(articleUrl, JSON.stringify(data)); + return Promise.resolve(data); + }) + ); + + ctx.state.data = { + title: `${types[type].name} - 中北大学`, + link: types[type].url, + description: `${types[type].name} - 中北大学`, + item: out, + }; +};