Skip to content

Commit

Permalink
feat: add 湖北工业大学新闻中心 (DIYgod#4366)
Browse files Browse the repository at this point in the history
  • Loading branch information
LandonLi authored Apr 2, 2020
1 parent 6a3d0be commit 06626a5
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
14 changes: 14 additions & 0 deletions assets/radar-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -1549,4 +1549,18 @@
},
],
},
'hbut.edu.cn': {
_name: '湖北工业大学',
www: [
{
title: '新闻中心',
docs: 'http://docs.rsshub.app/university.html#hu-bei-gong-ye-da-xue',
source: '/xwzx/:name',
target: (params) => {
const type = params.name.replace('.htm', '');
return type ? `/hbut/news/${type}` : '/hbut/news/tzgg';
},
},
],
},
});
12 changes: 12 additions & 0 deletions docs/university.md
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,18 @@ category 列表:

</Route>

## 湖北工业大学

### 新闻中心

<Route author="Lava-Swimmer" example="/hbut/news/tzgg" path="/hbut/news/:type" radar="1" :paramsDesc="['分类']">

| 通知公告 | 湖工要闻 | 学术活动 | 媒体湖工大 | 综合新闻 | 湖工故事 |
| -------- | -------- | -------- | ---------- | -------- | -------- |
| tzgg | hgyw | xshd | mthgd | zhxw | hggs |

</Route>

## 湖南科技大学

### 教务处通知
Expand Down
3 changes: 3 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2495,4 +2495,7 @@ router.get('/sckjt/news/:type?', require('./routes/sckjt/news'));
router.get('/blogs/diygod/animal-crossing', require('./routes/blogs/diygod/animal-crossing'));
router.get('/blogs/diygod/gk', require('./routes/blogs/diygod/gk'));

// 湖北工业大学
router.get('/hbut/news/:type', require('./routes/universities/hbut/news'));

module.exports = router;
42 changes: 42 additions & 0 deletions lib/routes/universities/hbut/news.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const resolve_url = require('url').resolve;

const base_url = 'https://www.hbut.edu.cn/xwzx';

const map = {
tzgg: '/tzgg.htm',
hgyw: '/hgyw.htm',
xshd: '/xshd.htm',
mthgd: '/mthgd.htm',
zhxw: '/zhxw.htm',
hggs: '/hggs.htm',
};

module.exports = async (ctx) => {
const type = ctx.params.type;
const link = `${base_url}${map[type]}`;

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: $('div.post.post1.post-14>div.con>ul.news_list>li')
.slice(0, 10)
.map((_, elem) => ({
link: resolve_url(link, $('span.news_title>a', elem).attr('href')),
title: $('a', elem).text(),
pubDate: new Date(`${$('span.news_meta', elem).text()}`).toString(),
}))
.get(),
};
};

0 comments on commit 06626a5

Please sign in to comment.