Skip to content

Commit

Permalink
Feat: add 清华大学
Browse files Browse the repository at this point in the history
  • Loading branch information
prnake committed Feb 15, 2020
1 parent 185bd53 commit dde680a
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/university.md
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,18 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet

</Route>

## 清华大学

### 清华大学校内信息发布平台

<Route author="prnake" example="/thu/zhongyao" path="/thu/:type" :paramsDesc="['默认为重要公告']">

| 重要公告 | 教务公告 | 科研通知 | 办公通知 | 海报列表 | 疫情防控 |
| -------- | -------- | -------- | -------- | -------- | :------: |
| zhongyao | jiaowu | keyan | bangong | haibao | yiqing |

</Route>

## 山东大学

### 软件学院通知
Expand Down
3 changes: 3 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,9 @@ router.get('/lit/jwc', require('./routes/universities/lit/jwc'));
router.get('/lit/xwzx/:name?', require('./routes/universities/lit/xwzx'));
router.get('/lit/tw/:name?', require('./routes/universities/lit/tw'));

// 清华大学
router.get('/thu/:type', require('./routes/universities/thu/index'));

// 北京大学
router.get('/pku/eecs/:type?', require('./routes/universities/pku/eecs'));
router.get('/pku/rccp/mzyt', require('./routes/universities/pku/rccp/mzyt'));
Expand Down
92 changes: 92 additions & 0 deletions lib/routes/universities/thu/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const resolve_url = require('url').resolve;

const base_url = 'https://thu.pka.moe';
const news_url = 'https://thu.pka.moe/http/77726476706e69737468656265737421e0f852882e3e6e5f301c9aa596522b2043f84ba24ebecaf8/f/';

module.exports = async (ctx) => {
const type = ctx.params.type;
let title,
path,
kind = 0;
switch (type) {
case 'zhongyao':
title = '重要公告';
path = 'zhongyaogonggao/more';
kind = 1;
break;
case 'keyan':
title = '科研通知';
path = 'keyantongzhi/more';
break;
case 'bangong':
title = '办公通知';
path = 'bangongtongzhi/more';
break;
case 'jiaowu':
title = '教务公告';
path = 'jiaowugonggao/more';
break;
case 'haibao':
title = '海报列表';
path = 'haibao/more';
break;
case 'yiqing':
title = '疫情防控';
path = 'yiqingfangkong/more';
kind = 1;
break;
default:
title = '重要公告';
path = 'zhongyaogonggao/more';
kind = 1;
}

const response = await got({
method: 'get',
url: news_url + path,
headers: {
Referer: base_url,
},
});

const $ = cheerio.load(response.data);
if (kind === 1) {
ctx.state.data = {
title: '清华大学 - ' + title,
link: news_url + path,
description: '清华大学内网信息发布平台 - ' + title,
item: $('table>tbody>tr')
.slice(0, 10)
.map((_, elem) => ({
link: resolve_url(base_url, $('td>a', elem).attr('href')),
title: $('td>a', elem).text(),
pubDate: new Date(
$('td>font>span', elem)
.text()
.replace(/(\d+).(\d+).(\d+).(\d+)/, '2020-$1-$2T$3:$4')
).toUTCString(),
}))
.get(),
};
} else {
ctx.state.data = {
title: '清华大学 - ' + title,
link: news_url + path,
description: '清华大学内网信息发布平台 - ' + title,
item: $('.cont_list>li')
.slice(0, 10)
.map((_, elem) => ({
link: resolve_url(base_url, $('a', elem).attr('href')),
title: $('a', elem).text(),
pubDate: new Date(
$('time', elem)
.text()
.replace(/(\d+).(\d+).(\d+)/, '$1-$2-$3')
).toUTCString(),
}))
.get(),
};
}
};

0 comments on commit dde680a

Please sign in to comment.