diff --git a/docs/university.md b/docs/university.md index c496be71ff..0361f3119f 100644 --- a/docs/university.md +++ b/docs/university.md @@ -970,6 +970,18 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet +## 天津大学 + +### 天津大学教务处 + + + +| 新闻动态 | 通知公告 | +| -------- | ------------ | +| news | notification | + + + ## 同济大学 ### 同济大学软件学院通知 diff --git a/lib/router.js b/lib/router.js index 2813576d2f..5883a4d53e 100644 --- a/lib/router.js +++ b/lib/router.js @@ -722,6 +722,9 @@ router.get('/wzbc/:type?', require('./routes/universities/wzbc/news')); // 河南大学 router.get('/henu/:type?', require('./routes/universities/henu/news')); +// 天津大学 +router.get('/tjpyu/ooa/:type?', require('./routes/universities/tjpyu/ooa')); + // 南开大学 router.get('/nku/jwc/:type?', require('./routes/universities/nku/jwc/index')); diff --git a/lib/routes/universities/tjpyu/ooa.js b/lib/routes/universities/tjpyu/ooa.js new file mode 100644 index 0000000000..f41ed1d93c --- /dev/null +++ b/lib/routes/universities/tjpyu/ooa.js @@ -0,0 +1,73 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const ooa_base_url = 'http://oaa.tju.edu.cn/'; +const repo_url = 'https://www.baidu.com'; + +module.exports = async (ctx) => { + const type = ctx.params && ctx.params.type; + let path, subtitle; + + switch (type) { + case 'news': + subtitle = '新闻动态'; + path = 'zytz'; + break; + case 'notification': + subtitle = '通知公告'; + path = 'zygg'; + break; + default: + subtitle = '新闻动态'; + path = 'zytz'; + } + let response = null; + try { + response = await got({ + method: 'get', + url: ooa_base_url + path, + headers: { + Referer: ooa_base_url, + }, + }); + } catch (e) { + // ignore error handler + // console.log(e); + } + + if (response === null) { + ctx.state.data = { + title: '天津大学教务处 - ' + subtitle, + link: ooa_base_url + path, + description: '链接失效' + ooa_base_url + path, + item: [ + { + title: '提示信息', + link: repo_url, + description: `

请到此处提交Issue

`, + }, + ], + }; + } else { + const $ = cheerio.load(response.data); + const list = $('.iplan > ul > li').slice(0, 10); + + ctx.state.data = { + title: '天津大学教务处 - ' + subtitle, + link: ooa_base_url + path, + description: null, + item: + list && + list + .map((index, item) => ({ + title: $('h2', item) + .text() + .replace(/(\d+)-(\d+)-(\d+)$/, ''), // remove duplicate date at the end of h2 element + pubDate: new Date($('span', item).text()).toUTCString(), + link: $('a', item).attr('href'), + description: $('p', item).text(), + })) + .get(), + }; + } +};