feat: add dlmu news feed. (#4280)

This commit is contained in:
Zhou Yang
2020-03-19 19:30:16 +08:00
committed by GitHub
parent 77ccb135df
commit 0a9d6a9f04
3 changed files with 63 additions and 0 deletions

View File

@@ -191,6 +191,18 @@ pageClass: routes
</Route>
## 大连海事大学
### 新闻网
<Route author="arjenzhou" example="/dlmu/news/hdyw" path="/dlmu/news/:type" :paramsDesc="['默认为 `hdyw`']">
| 海大要闻 | 媒体海大 | 综合新闻 | 院系风采 | 海大校报 | 理论园地 | 海大讲坛 | 艺文荟萃 |
| :------: | :------: | :------: | :------: | :------: | :------: | :------: | :------: |
| hdyw | mthd | zhxw | yxfc | hdxb | llyd | hdjt | ywhc |
</Route>
## 电子科技大学
### 教务处

View File

@@ -2405,4 +2405,7 @@ router.get('/socialclub/events/:game?', require('./routes/socialclub/events'));
// 湖北大学
router.get('/hubu/news/:type', require('./routes/universities/hubu/news'));
// 大连海事大学
router.get('/dlmu/news/:type', require('./routes/universities/dlmu/news'));
module.exports = router;

View File

@@ -0,0 +1,48 @@
const got = require('@/utils/got');
const iconv = require('iconv-lite');
const cheerio = require('cheerio');
const resolve_url = require('url').resolve;
const base_url = 'http://news.dlmu.edu.cn';
const map = {
hdyw: '/hdyw.htm',
mthd: '/mthd.htm',
zhxw: '/zhxw.htm',
yxfc: '/yxfc.htm',
hdxb: '/hdxb.htm',
llyd: '/llyd.htm',
hdjt: '/hdjt.htm',
ywhc: '/ywhc.htm',
};
module.exports = async (ctx) => {
const type = ctx.params.type;
const link = map.hasOwnProperty(type) ? `${base_url}${map[type]}` : `${base_url}/hdyw.htm`;
const response = await got({
method: 'get',
url: link,
responseType: 'buffer',
headers: {
Referer: base_url,
},
});
const $ = cheerio.load(iconv.decode(response.data, 'utf-8'));
ctx.state.data = {
link: base_url,
title: '大连海事大学新闻',
item: $('.n-Box .n-right .n-pic-box .n-news dl')
.slice(0, 10)
.map((_, element) => ({
link: resolve_url(base_url, $('dd a', element).attr('href')),
title: $('dd a', element).text(),
description: $('dd p', element).text(),
pubDate: new Date(
$('i', element)
.text()
.slice(1, -1)
),
}))
.get(),
};
};