增加山东大学能源与动力工程学院通知 (#866)

This commit is contained in:
Jianing Wang 2018-10-12 01:12:24 +08:00 committed by DIYgod
parent 005c498af8
commit 1a64ac369c
3 changed files with 64 additions and 0 deletions

View File

@ -1247,6 +1247,14 @@ category 列表:
</route>
<route name="能源与动力工程学院通知" author="Ji4n1ng" example="/sdu/epe/0" path="/universities/sdu/epe/:type?" :paramsDesc="['默认为 `0`']">
| 学院动态 | 通知公告 | 学术论坛 |
| -------- | -------- | -------- |
| 0 | 1 | 2 |
</route>
## 传统媒体
### 央视新闻

View File

@ -561,6 +561,7 @@ router.get('/sdu/grad/academic', require('./routes/universities/sdu/grad/academi
router.get('/sdu/sc/:type?', require('./routes/universities/sdu/sc'));
router.get('/sdu/cmse/:type?', require('./routes/universities/sdu/cmse'));
router.get('/sdu/mech/:type?', require('./routes/universities/sdu/mech'));
router.get('/sdu/epe/:type?', require('./routes/universities/sdu/epe'));
// ifanr
router.get('/ifanr/appso', require('./routes/ifanr/appso'));

View File

@ -0,0 +1,55 @@
const axios = require('../../../utils/axios');
const cheerio = require('cheerio');
const url = require('url');
const host = 'http://www.epe.sdu.edu.cn/';
const typelist = ['学院动态', '通知公告', '学术论坛'];
const urlList = ['zxzx/xydt.htm', 'zxzx/tzgg.htm', 'zxzx/xslt.htm'];
module.exports = async (ctx) => {
const type = parseInt(ctx.params.type) || 0;
const link = url.resolve(host, urlList[type]);
const response = await axios.get(link);
const $ = cheerio.load(response.data);
const list = $('#page_right_main li a')
.map((i, e) => $(e).attr('href'))
.get();
const out = await Promise.all(
list.filter((e) => e.startsWith('../info')).map(async (itemUrl) => {
itemUrl = url.resolve(host, itemUrl.slice('3'));
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await axios.get(itemUrl);
const $ = cheerio.load(response.data);
const rawDate = $('#show_info')
.text()
.split(/\s{4}/);
const date = rawDate[0].split('')[1];
const single = {
title: $('#show_title')
.text()
.trim(),
link: itemUrl,
author: '山东大学能源与动力工程学院',
description: $('#show_content').html(),
pubDate: new Date(date),
};
ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60);
return Promise.resolve(single);
})
);
ctx.state.data = {
title: `山东大学能源与动力工程学院${typelist[type]}`,
link,
item: out,
};
};