Skip to content

Commit

Permalink
feat(route): sspu (#14050)
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyRL authored Dec 15, 2023
1 parent a1644ac commit f7f8b7a
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
44 changes: 44 additions & 0 deletions lib/v2/sspu/jwc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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 { listId } = ctx.params;
const baseUrl = 'https://jwc.sspu.edu.cn';

const { data: response, url: link } = await got(`${baseUrl}/${listId}/list.htm`);
const $ = cheerio.load(response);

const list = $('.news_list .news')
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 15)
.toArray()
.map((item) => {
item = $(item);
const title = item.find('.news_title a');
return {
title: title.attr('title'),
link: `${baseUrl}${title.attr('href')}`,
};
});

const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: response } = await got(item.link);
const $ = cheerio.load(response);

item.description = $('.wp_articlecontent').html();
item.pubDate = timezone(parseDate($('.arti_update').text(), 'YYYY-MM-DD HH:mm:ss'), +8);

return item;
})
)
);

ctx.state.data = {
title: $('head title').text(),
link,
item: items,
};
};
3 changes: 3 additions & 0 deletions lib/v2/sspu/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/jwc/:listId': ['TonyRL'],
};
13 changes: 13 additions & 0 deletions lib/v2/sspu/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'sspu.edu.cn': {
_name: '上海第二工业大学',
jwc: [
{
title: '教务处',
docs: 'https://docs.rsshub.app/university#shang-hai-di-er-gong-ye-da-xue',
source: ['/jwc/:listId/list.htm'],
target: '/sspu/jwc/:listId',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/sspu/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/jwc/:listId', require('./jwc'));
};
10 changes: 10 additions & 0 deletions website/docs/routes/university.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2335,6 +2335,16 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE\_TL
| notice | news | policy |
</Route>

## 上海第二工业大学 {#shang-hai-di-er-gong-ye-da-xue}

### 教务处 {#shang-hai-di-er-gong-ye-da-xue-jiao-wu-chu}

<Route author="TonyRL" example="/sspu/jwc/:listId" path="/sspu/jwc/897" paramsDesc={['专栏 ID,见下表']} radar="1">
| 学生专栏 | 教师专栏 |
| -------- | -------- |
| 897 | 898 |
</Route>

## 上海电力大学 {#shang-hai-dian-li-da-xue}

### 新闻网与学院通知 {#shang-hai-dian-li-da-xue-xin-wen-wang-yu-xue-yuan-tong-zhi}
Expand Down

0 comments on commit f7f8b7a

Please sign in to comment.