feat: 添加山东大学计算机科学与技术学院 RSS (#2267)

* 添加山东大学计算机科学与技术学院通知

* 添加山东大学计算机科学与技术学院通知

* add .toUTCString()
This commit is contained in:
sxb_201
2019-06-02 12:37:45 +08:00
committed by DIYgod
parent f4bbba1b89
commit 426450d7ec
3 changed files with 72 additions and 0 deletions

View File

@@ -632,6 +632,16 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet
</Route>
### 计算机科学与技术学院通知
<Route author="suxb201" example="/sdu/cs/0" path="/universities/sdu/cs/:type?" :paramsDesc="['默认为 `0`']">
| 学院公告 | 学术报告 | 新闻动态 |
| -------- | -------- | -------- |
| 0 | 1 | 2 |
</Route>
## 上海大学
### 上海大学教务处通知公告

View File

@@ -635,6 +635,7 @@ router.get('/hust/aia/notice/:type?', require('./routes/universities/hust/aia/no
// 山东大学
router.get('/sdu/grad/academic', require('./routes/universities/sdu/grad/academic'));
router.get('/sdu/sc/:type?', require('./routes/universities/sdu/sc'));
router.get('/sdu/cs/:type?', require('./routes/universities/sdu/cs'));
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'));

View File

@@ -0,0 +1,61 @@
const axios = require('@/utils/axios');
const cheerio = require('cheerio');
const url = require('url');
const host = 'http://www.cs.sdu.edu.cn/';
const typelist = ['学院公告', '学术报告', '新闻动态'];
const urlList = ['index/xygg.htm', 'xwgg/xsbg.htm', 'xwgg/xyxw.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 dateDict = {};
const list = $('.sub_text .news-list')
.slice(0, 10)
.map((i, e) => {
const divs = $(e).children();
const tlink =
'http://www.cs.sdu.edu.cn/' +
$('a', divs[1])
.attr('href')
.substring(3);
dateDict[tlink] = new Date($(divs[2]).text()).toUTCString();
return tlink;
})
.get();
const out = await Promise.all(
list.map(async (itemUrl) => {
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 single = {
title: $('#newsTitle')
.text()
.trim(),
author: '山东大学计算机科学与技术学院',
description: $('.v_news_content').html(),
pubDate: dateDict[itemUrl],
link: itemUrl,
};
ctx.cache.set(itemUrl, JSON.stringify(single));
return Promise.resolve(single);
})
);
ctx.state.data = {
title: `山东大学计算机科学与技术学院${typelist[type]}通知`,
link,
item: out,
};
};