diff --git a/docs/university.md b/docs/university.md index ff7d573bd..e054ce68b 100644 --- a/docs/university.md +++ b/docs/university.md @@ -191,6 +191,18 @@ pageClass: routes +## 大连海事大学 + +### 新闻网 + + + +| 海大要闻 | 媒体海大 | 综合新闻 | 院系风采 | 海大校报 | 理论园地 | 海大讲坛 | 艺文荟萃 | +| :------: | :------: | :------: | :------: | :------: | :------: | :------: | :------: | +| hdyw | mthd | zhxw | yxfc | hdxb | llyd | hdjt | ywhc | + + + ## 电子科技大学 ### 教务处 diff --git a/lib/router.js b/lib/router.js index 958d40cd9..336d0cbb9 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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; diff --git a/lib/routes/universities/dlmu/news.js b/lib/routes/universities/dlmu/news.js new file mode 100644 index 000000000..c330e0065 --- /dev/null +++ b/lib/routes/universities/dlmu/news.js @@ -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(), + }; +};