feat:add 湖北大学通知 (#4237)

This commit is contained in:
cijiugechu 2020-03-17 11:56:29 +08:00 committed by GitHub
parent 75a69455a2
commit 46d8f36616
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 0 deletions

View File

@ -496,6 +496,18 @@ category 列表:
<Route author="fengkx" example="/scnu/cs/match" path="/scnu/cs/match"/>
## 湖北大学
### 新闻通知
<Route author="cijiugechu" example="/hubu/news/zhxw" path="/universities/hubu/news/:type?" :paramsDesc="['默认为 `zhxw`']">
| 综合新闻 | 湖大要闻 | 通知公告 | 学术学者学生 | 媒体湖大 |
| -------- | -------- | -------- | ------------ | -------- |
| zhxw | hdyw | tzgg | xsxzxs | mthd |
</Route>
## 华中科技大学
### 人工智能和自动化学院通知

View File

@ -2360,4 +2360,7 @@ router.get('/moxingfans', require('./routes/moxingfans'));
// Chiphell
router.get('/chiphell/forum/:forumId?', require('./routes/chiphell/forum'));
// 湖北大学
router.get('/hubu/news/:type', require('./routes/universities/hubu/news'));
module.exports = router;

View File

@ -0,0 +1,45 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const resolve_url = require('url').resolve;
const base_url = 'http://www.hubu.edu.cn/index';
const map = {
zhxw: '/zhxw.htm',
hdyw: '/hdyw.htm',
tzgg: '/tzgg.htm',
xsxzxs: '/xsxzxs.htm',
mthd: '/mthd.htm',
};
module.exports = async (ctx) => {
const type = ctx.params.type;
const link = `${base_url}${map[type]}`;
const date = new Date();
const response = await got({
method: 'get',
url: link,
headers: {
Referer: link,
},
});
const $ = cheerio.load(response.data);
ctx.state.data = {
link: link,
title: $('title').text(),
item: $('.list>ul>li')
.slice(0, 10)
.map((_, elem) => ({
link: resolve_url(link, $('a', elem).attr('href')),
title: $('a', elem).text(),
pubDate:
new Date(`${date.getFullYear()}-${$('span.food-time', elem).text()}`) > date
? new Date(`${date.getFullYear() - 1}-${$('span.food-time', elem).text()}`).toUTCString()
: new Date(`${date.getFullYear()}-${$('span.food-time', elem).text()}`).toUTCString(),
}))
.get(),
};
};