feat: 增加四川大学学工部通知公告 (#3062)

This commit is contained in:
Steve Lee
2019-09-15 12:41:03 +08:00
committed by DIYgod
parent e8a40bc0d2
commit 67eba5dfd6
3 changed files with 55 additions and 0 deletions

View File

@@ -830,6 +830,10 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet
<Route author="KXXH" example="/scu/jwc/notice" path="/scu/jwc/notice" />
### 学工部通知公告
<Route author="stevelee477" example="/scu/xg/notice" path="/scu/xg/notice" />
## 四川旅游学院
### 信息与工程学院动态公告列表

View File

@@ -1180,6 +1180,7 @@ router.get('/babykingdom/:id/:order?', require('./routes/babykingdom'));
// 四川大学
router.get('/scu/jwc/notice', require('./routes/universities/scu/jwc'));
router.get('/scu/xg/notice', require('./routes/universities/scu/xg'));
// 浙江工商大学
router.get('/zjgsu/tzgg', require('./routes/universities/zjgsu/tzgg/scripts'));

View File

@@ -0,0 +1,50 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
async function load_detail(list, cache) {
return await Promise.all(
list.map(async (item) => {
const notice_item = cheerio.load(item);
const url = 'http://xsc.scu.edu.cn' + notice_item('a').attr('href');
return await cache.tryGet(url, async () => {
const detail_response = await got({
method: 'get',
url: url,
headers: {
Referer: 'http://xsc.scu.edu.cn/WEBSITE/XG',
Host: 'xsc.scu.edu.cn',
},
});
const detail = cheerio.load(detail_response.data);
return {
title: notice_item('a').attr('title'),
description: detail('.news-content').html(),
link: url,
};
});
})
);
}
module.exports = async (ctx) => {
const response = await got({
method: 'get',
url: 'http://xsc.scu.edu.cn/WEBSITE/XG',
headers: {
Host: 'xsc.scu.edu.cn',
},
});
const data = response.data;
const $ = cheerio.load(data);
const list = $('.news-pannel.notice-news > .news-body > .news-list > ul > li').get();
const detail = await load_detail(list, ctx.cache);
ctx.state.data = {
title: '四川大学学工部 - 通知公告',
link: 'http://xsc.scu.edu.cn/WEBSITE/XG',
item: detail,
};
};