feat(route): tju cic news, notification and forum (#10223)

* feat(route): tju cic news, notification and forum

* chore: update

* chore: update

* chore: reserve attachments in each feed
This commit is contained in:
SUPER 2022-07-16 21:30:13 +08:00 committed by GitHub
parent 54aea1e4e7
commit 1a8e46d9eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 160 additions and 5 deletions

View File

@ -48,12 +48,22 @@ Note: [Source website](https://gs.bjtu.edu.cn/) only provides articles in Chines
## Tianjin University
### College of Intelligence and Computing
<RouteEn author="SuperPung" example="/tju/cic/news" path="/tju/cic/:type?" :paramsDesc="['default `news`']">
| College News | Notification | TJU Forum for CIC |
| :----------: | :----------: | :---------------: |
| news | notification | forum |
</RouteEn>
### The Office of Academic Affairs
<RouteEn author="AmosChenYQ SuperPung" example="/tju/oaa/news" path="/tju/oaa/:type?" :paramsDesc="['default `news`']">
| News | Notification |
| ---- | ------------ |
| :--: | :----------: |
| news | notification |
</RouteEn>

View File

@ -2385,12 +2385,22 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS
## 天津大学
### 天津大学教务处
### 智能与计算学部
<Route author="AmosChenYQ SuperPung" example="/tju/oaa/news" path="/tju/oaa/:type?" :paramsDesc="['默认为`news`']">
<Route author="SuperPung" example="/tju/cic/news" path="/tju/cic/:type?" :paramsDesc="['默认为 `news`']">
| 新闻动态 | 通知公告 |
| ---- | ------------ |
| 学部新闻 | 通知公告 | 北洋智算论坛 |
| :--: | :----------: | :----: |
| news | notification | forum |
</Route>
### 教务处
<Route author="AmosChenYQ SuperPung" example="/tju/oaa/news" path="/tju/oaa/:type?" :paramsDesc="['默认为 `news`']">
| 新闻动态 | 通知公告 |
| :--: | :----------: |
| news | notification |
</Route>

113
lib/v2/tju/cic/index.js Normal file
View File

@ -0,0 +1,113 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const cic_base_url = 'http://cic.tju.edu.cn/';
const repo_url = 'https://github.com/DIYgod/RSSHub/issues';
const pageType = (href) => {
if (!href.startsWith('http')) {
return 'in-site';
}
const url = new URL(href);
if (url.hostname === 'cic.tju.edu.cn') {
return 'tju-cic';
} else {
return 'unknown';
}
};
module.exports = async (ctx) => {
const type = ctx.params && ctx.params.type;
let path, subtitle;
switch (type) {
case 'news':
subtitle = '学部新闻';
path = 'xwzx/xyxw.htm';
break;
case 'notification':
subtitle = '通知公告';
path = 'xwzx/tzgg.htm';
break;
case 'forum':
subtitle = '北洋智算论坛';
path = 'byzslt.htm';
break;
default:
subtitle = '学部新闻';
path = 'xwzx/xyxw.htm';
}
let response = null;
try {
response = await got(cic_base_url + path, {
headers: {
Referer: cic_base_url,
},
});
} catch (e) {
// ignore error handler
// console.log(e);
}
if (response === null) {
ctx.state.data = {
title: '天津大学智能与计算学部 - ' + subtitle,
link: cic_base_url + path,
description: '链接失效' + cic_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 = $('.wenzi_list_ul > li')
.map((_index, item) => {
const href = $('a', item).attr('href');
const type = pageType(href);
return {
title: $('a', item).text(),
link: type === 'in-site' ? cic_base_url + href : href,
type,
};
})
.get();
const items = await Promise.all(
list.map((item) => {
switch (item.type) {
case 'tju-cic':
case 'in-site':
return ctx.cache.tryGet(item.link, async () => {
let detailResponse = null;
try {
detailResponse = await got(item.link);
const content = cheerio.load(detailResponse.data);
item.pubDate = timezone(parseDate(content('.news_info > span').first().text(), 'YYYY年MM月DD日 HH:mm'), +8);
content('.news_tit').remove();
content('.news_info').remove();
item.description = content('.con_news_body > div').html();
} catch (e) {
// ignore error handler
}
return item;
});
default:
return item;
}
})
);
ctx.state.data = {
title: '天津大学智能与计算学部 - ' + subtitle,
link: cic_base_url + path,
description: null,
item: items,
};
}
};

View File

@ -1,3 +1,4 @@
module.exports = {
'/cic/:type?': ['SuperPung'],
'/oaa/:type?': ['AmosChenYQ', 'SuperPung'],
};

View File

@ -1,6 +1,26 @@
module.exports = {
'tju.edu.cn': {
_name: '天津大学',
cic: [
{
title: '智能与计算学部 - 学部新闻',
docs: 'https://docs.rsshub.app/university.html#tian-jin-da-xue',
source: ['/xwzx/xyxw.htm', '/'],
target: '/tju/cic/news',
},
{
title: '智能与计算学部 - 通知公告',
docs: 'https://docs.rsshub.app/university.html#tian-jin-da-xue',
source: ['/xwzx/tzgg.htm', '/'],
target: '/tju/cic/notification',
},
{
title: '智能与计算学部 - 北洋智算论坛',
docs: 'https://docs.rsshub.app/university.html#tian-jin-da-xue',
source: ['/byzslt.htm', '/'],
target: '/tju/cic/forum',
},
],
oaa: [
{
title: '教务处 - 新闻动态',

View File

@ -1,3 +1,4 @@
module.exports = function (router) {
router.get('/cic/:type?', require('./cic'));
router.get('/oaa/:type?', require('./oaa'));
};