diff --git a/README.md b/README.md index 2b59a93b69..4ff322eb9c 100644 --- a/README.md +++ b/README.md @@ -199,6 +199,9 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 - 教务处通知 - 图书馆通知 - 计算机学院竞赛通知 +- 西南科技大学 + - 教务处通知 + - 计科学院通知 - Keep - 运动日记 - 起点 diff --git a/docs/README.md b/docs/README.md index aa9baffa6e..483062edc3 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1424,6 +1424,24 @@ id, 专辑 id, 可在对应专辑页面的 URL 中找到 参数: type,1 为教务新闻,2 为教务公告 +## 西南科技大学 + +### 教务处通知 + +举例: [https://rsshub.app/swust/jwc/1](https://rsshub.app/swust/jwc/1) + +路由: `/swust/jwc/:type` + +参数: type, 1 为通知公告, 2 为站点新闻 + +### 计科学院通知 + +举例: [https://rsshub.app/swust/cs/1](https://rsshub.app/swust/cs/1) + +路由: `swust/cs/:type` + +参数: type, 1 为新闻动态, 2 为学术动态, 3 为通知公告, 4 为教研动态 + ## 新京报 ### 栏目 diff --git a/router.js b/router.js index 9a821e86a2..21111405dc 100755 --- a/router.js +++ b/router.js @@ -310,6 +310,10 @@ router.get('/shmtu/events', require('./routes/shmtu/events')); router.get('/shmtu/notes', require('./routes/shmtu/notes')); router.get('/shmtu/jwc/:type', require('./routes/shmtu/jwc')); +// SWUST +router.get('/swust/jwc/:type', require('./routes/swust/jwc')); +router.get('/swust/cs/:type', require('./routes/swust/cs')); + // 新京报 router.get('/bjnews/:cat', require('./routes/bjnews/news')); diff --git a/routes/swust/cs.js b/routes/swust/cs.js new file mode 100644 index 0000000000..24f3961d97 --- /dev/null +++ b/routes/swust/cs.js @@ -0,0 +1,68 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); +const config = require('../../config'); + +module.exports = async (ctx) => { + const host = 'http://www.cs.swust.edu.cn/'; + let type = ctx.params.type; + let info = '新闻动态'; + let word = 'news'; + if (type === '2') { + info = '学术动态'; + word = 'academic'; + } else if (type === '3') { + info = '通知公告'; + word = 'notice'; + } else if (type === '4') { + info = '教研动态'; + word = 'Teach_Research'; + } else { + type = '1'; + } + + const response = await axios({ + method: 'get', + url: host + word, + headers: { + 'User-Agent': config.ua, + Referer: host, + }, + }); + + const $ = cheerio.load(response.data); + const text = $('a', '.list.list3'); + + ctx.state.data = { + title: `西南科技大学 计科学院 ${info}`, + link: host + word, + description: `西南科技大学 计科学院 ${info}`, + item: + text && + text + .map((index, item) => { + item = $(item); + return { + title: $('.imgdesc', item) + .find('.imgtitle') + .text(), + description: $('.imgdesc', item) + .find('.imgtext') + .text(), + pubDate: new Date( + Date.parse( + $('.imgdesc', item) + .contents() + .filter(function() { + return this.nodeType === 3; + }) + .text() + .replace('[', '') + .replace(']', '') + ) + ), + link: host + item.attr('href'), + }; + }) + .get(), + }; +}; diff --git a/routes/swust/jwc.js b/routes/swust/jwc.js new file mode 100644 index 0000000000..4fa0c30027 --- /dev/null +++ b/routes/swust/jwc.js @@ -0,0 +1,65 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); +const config = require('../../config'); + +module.exports = async (ctx) => { + const host = 'http://www.dean.swust.edu.cn'; + let type = ctx.params.type; + + let info = '通知公告'; + let word = 'notices/'; + + if (type === '2') { + info = '站点新闻'; + word = 'news/'; + } else { + type = '1'; + } + + const web = 'http://www.dean.swust.edu.cn/xml/' + word + 'index.xml'; + const response = await axios({ + method: 'get', + url: web, + headers: { + 'User-Agent': config.ua, + Referer: host, + }, + }); + + const data = response.data; + + const $ = cheerio.load(data, { + xmlMode: true, + }); + const list = $('entrity'); + + ctx.state.data = { + title: '西南科技大学 教务处 ' + info, + link: web, + description: $('title') + .first() + .text(), + item: + list && + list + .map((index, item) => { + item = $(item); + return { + title: item.find('title').text(), + description: item.find('summary').text(), + pubDate: new Date( + Date.parse( + item + .find('date') + .text() + .replace('年', '-') + .replace('月', '-') + .replace('日', '') + ) + ), + link: host + '/xml/' + word + item.attr('id') + '.xml', + }; + }) + .get(), + }; +};