feat: Add RSS for OOA of Tianjin University (#4054)

This commit is contained in:
AmosChenYQ
2020-02-25 00:09:09 +08:00
committed by GitHub
parent 0f7de056ec
commit 4bb8c813a1
3 changed files with 88 additions and 0 deletions
+12
View File
@@ -970,6 +970,18 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet
</Route>
## 天津大学
### 天津大学教务处
<Route author="AmosChenYQ" example="/tjpyu/ooa/news" path="/universities/tjpyu/ooa/:type" :paramsDesc="['默认为`news`']">
| 新闻动态 | 通知公告 |
| -------- | ------------ |
| news | notification |
</Route>
## 同济大学
### 同济大学软件学院通知
+3
View File
@@ -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'));
+73
View File
@@ -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: `<h2>请到<a href=${repo_url}>此处</a>提交Issue</h2>`,
},
],
};
} 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(),
};
}
};