feat: add 桂林电子科技大学新闻资讯 (#3281)

This commit is contained in:
cssxsh
2019-10-18 12:18:45 +08:00
committed by DIYgod
parent ff7caf3dd7
commit d8be065855
3 changed files with 111 additions and 0 deletions
+13
View File
@@ -275,6 +275,19 @@ xskb1 对应 http://www.auto.uestc.edu.cn/index/xskb1.htm
<Route author="Xiaotouming" example="/gdoujwc" path="/gdoujwc"/>
## 桂林电子科技大学
### 新闻资讯
<Route author="cssxsh" example="/guet/xwzx/xykx" path="/guet/xwzx/:type" :paramsDesc="['资讯类型,如下表']">
| 桂电要闻 | 文明校园建设 | 桂电新闻 | 校园快讯 | 学院动态 | 媒体桂电 | 通知公告 | 招标公示 | 学术活动 |
| -------- | ------------ | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
| gdyw | wmxyjs | gdxw | xykx | xydt | mtgd | tzgg | zbgs | xshd |
注 1: 不要吐槽拼音缩写,缩写原本的 URL 构成就这样。
</Route>
## 哈尔滨工程大学
### 本科生院工作通知
+3
View File
@@ -1851,6 +1851,9 @@ router.get('/4gamers/tag/:tag', require('./routes/4gamers/tag'));
// 大麦网
router.get('/damai/activity/:city/:category/:subcategory/:keyword?', require('./routes/damai/activity'));
// 桂林电子科技大学新闻资讯
router.get('/guet/xwzx/:type?', require('./routes/guet/news'));
// はてな匿名ダイアリー
router.get('/hatena/anonymous_diary/archive', require('./routes/hatena/anonymous_diary/archive'));
+95
View File
@@ -0,0 +1,95 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const host = 'https://www.guet.edu.cn';
const infos = {
gdyw: {
path: '/xwzx/gdyw.htm',
title: '桂电要闻',
},
wmxyjs: {
path: '/xwzx/wmxyjs.htm',
title: '文明校园建设',
},
gdxw: {
path: '/xwzx/gdxw.htm',
title: '桂电新闻',
},
xykx: {
path: '/xwzx/xykx.htm',
title: '校园快讯',
},
xydt: {
path: '/xwzx/xydt.htm',
title: '学院动态',
},
mtgd: {
path: '/xwzx/mtgd.htm',
title: '媒体桂电',
},
tzgg: {
path: '/xwzx/tzgg.htm',
title: '通知公告',
},
zbgs: {
path: '/xwzx/mtgd.htm',
title: '招标公示',
},
xshd: {
path: '/xwzx/tzgg.htm',
title: '学术活动',
},
};
module.exports = async (ctx) => {
const type = ctx.params.type || 'gdyw';
if (!infos[type]) {
throw Error('参数不在可选范围之内');
}
const path = infos[type].path;
const response = await got(path, {
baseUrl: host,
});
const data = response.data;
const $ = cheerio.load(data);
const list = $('tr[id^="line"]').find('a');
const item = await Promise.all(
list
.map(async (index, element) => {
const href = $(element).attr('href');
const path = href && href.replace(/\.\./, '');
const link = host + path;
const item = await ctx.cache.tryGet(link, async () => {
const result = await got.get(link);
const $ = cheerio.load(result.data);
const title = $('#newTitle').text();
const publish = $('.newsPublish').text();
const time = publish
.replace(/(发布时间:|日|分)/g, '')
.replace(/(年|月)/g, '-')
.replace(/时/g, ':');
const pubDate = new Date(`${time} GMT+0800`).toUTCString();
const description = $('div[id^="vsb_content"]').html();
const single = {
title: title,
link: link,
description: description,
pubDate: pubDate,
};
return single;
});
return Promise.resolve(item);
})
.get()
);
ctx.state.data = {
title: infos[type].title,
link: response.url,
item: item,
};
};