Skip to content

Commit

Permalink
fix(route/sjtu): gs
Browse files Browse the repository at this point in the history
  • Loading branch information
dzx-dzx committed Jul 5, 2023
1 parent 96209ce commit a10999c
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 100 deletions.
20 changes: 16 additions & 4 deletions docs/university.md
Original file line number Diff line number Diff line change
Expand Up @@ -2590,11 +2590,23 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS

### 研究生通知公告

<Route author="mzr1996" example="/sjtu/gs/tzgg/pyxx" path="/sjtu/gs/tzgg/:type?" :paramsDesc="['默认列举所有通知公告']">
<Route author="dzx-dzx" example="/sjtu/gs/enroll/59" path="/sjtu/gs/:type/:num?" :paramsDesc="['类别', '细分类别, 仅对`type`为`enroll`或`exchange`有效']">

| 通知公告 | 工作信息 | 招生信息 | 培养信息 | 学位学科 | 国际交流 | 创新工程 |
| -------- | -------- | -------- | -------- | -------- | -------- | -------- |
|| gzxx | xwxx1 | pyxx | xwxx | gjjl | cxgc |
| 工作信息 | 招生信息 | 培养信息 | 学位学科 | 国际交流 | 创新工程 |
| -------- | -------- | -------- | -------- | -------- | -------- |
| work | enroll | train | degree | exchange | xsjy |

`type``enroll`, `num`可选字段:

| 58 | 59 | 60 | 61 | 62 |
| -------- | -------- | ---------- | -------- | -------- |
| 博士招生 | 硕士招生 | 港澳台招生 | 考点信息 | 院系动态 |

`type``exchange`, `num`可选字段:

| 67 | 68 | 69 | 70 | 71 |
| -------------- | -------------- | -------------- | -------------- | -------------- |
| 国家公派研究生 | 国际化培养资助 | 校际交换与联培 | 交流与合作项目 | 项目招募与宣讲 |

</Route>

Expand Down
2 changes: 1 addition & 1 deletion lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ router.get('/sjtu/seiee/academic', lazyloadRouteHandler('./routes/universities/s
router.get('/sjtu/seiee/bjwb/:type', lazyloadRouteHandler('./routes/universities/sjtu/seiee/bjwb'));
router.get('/sjtu/seiee/xsb/:type?', lazyloadRouteHandler('./routes/universities/sjtu/seiee/xsb'));

router.get('/sjtu/gs/tzgg/:type?', lazyloadRouteHandler('./routes/universities/sjtu/gs/tzgg'));
// router.get('/sjtu/gs/tzgg/:type?', lazyloadRouteHandler('./routes/universities/sjtu/gs/tzgg'));
router.get('/sjtu/jwc/:type?', lazyloadRouteHandler('./routes/universities/sjtu/jwc'));
router.get('/sjtu/tongqu/:type?', lazyloadRouteHandler('./routes/universities/sjtu/tongqu/activity'));
router.get('/sjtu/yzb/zkxx/:type', lazyloadRouteHandler('./routes/universities/sjtu/yzb/zkxx'));
Expand Down
31 changes: 0 additions & 31 deletions lib/routes/universities/sjtu/gs/tzgg.js

This file was deleted.

64 changes: 0 additions & 64 deletions lib/routes/universities/sjtu/gs/utils.js

This file was deleted.

55 changes: 55 additions & 0 deletions lib/v2/sjtu/gs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');

module.exports = async (ctx) => {
const type = ctx.params.type;
const num = ctx.params.num ?? '';

const rootUrl = 'https://www.gs.sjtu.edu.cn';
const currentUrl = `${rootUrl}/announcement/${type}/${num}`;
const response = await got({
method: 'get',
url: currentUrl,
});

const $ = cheerio.load(response.data);

const list = $('a.announcement-item')
.map((_, item) => {
item = $(item);

const day = item.find('.day').text().trim().replace('.', '-');
const year = item.find('.month').text().trim();

return {
title: item.find('.title').text().trim(),
link: `${item.attr('href').startsWith('http') ? '' : rootUrl}${item.attr('href')}`,
pubDate: timezone(parseDate(`${year}-${day}`, 'YYYY-MM-DD'), +8),
};
})
.get();

const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);

item.description = (item.link.includes('mp.weixin.qq.com/') ? content('#js_content') : content('.page-content')).html();

Check failure

Code scanning / CodeQL

Incomplete URL substring sanitization High

'
mp.weixin.qq.com/
' can be anywhere in the URL, and arbitrary hosts may come before or after it.

return item;
})
)
);

ctx.state.data = {
title: `${num === '' ? '' : `${$('.category-nav-block .active').text().trim()} - `}${$('div.inner-banner-text .title').text().trim()} - ${$('title').text()}`,
link: currentUrl,
item: items,
};
};
3 changes: 3 additions & 0 deletions lib/v2/sjtu/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/gs/:type/:num?': ['dzx-dzx'],
};
13 changes: 13 additions & 0 deletions lib/v2/sjtu/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'sjtu.edu.cn': {
_name: '上海交通大学',
gs: [
{
title: '研究生通知公告',
docs: 'https://docs.rsshub.app/university.html#shang-hai-jiao-tong-da-xue-yan-jiu-sheng-tong-zhi-gong-gao',
source: ['*'],
target: '/gs/:type/:num?',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/sjtu/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/gs/:type/:num?', require('./gs'));
};

0 comments on commit a10999c

Please sign in to comment.