feat: add 上海科技大学活动通知 (#4714)

This commit is contained in:
Ethan Shen
2020-05-11 18:34:27 +08:00
committed by GitHub
parent d3d17575b4
commit 1091f4ce04
3 changed files with 40 additions and 0 deletions

View File

@@ -1144,6 +1144,10 @@ type 列表:
## 上海科技大学 ## 上海科技大学
### 活动通知
<Route author="nczitzk" example="/shanghaitech/activity" path="/shanghaitech/activity"/>
### 信息科技与技术学院活动 ### 信息科技与技术学院活动
<Route author="HenryQW" example="/shanghaitech/sist/activity" path="/shanghaitech/sist/activity"/> <Route author="HenryQW" example="/shanghaitech/sist/activity" path="/shanghaitech/sist/activity"/>

View File

@@ -583,6 +583,7 @@ router.get('/hit/jwc', require('./routes/universities/hit/jwc'));
router.get('/hit/today/:category', require('./routes/universities/hit/today')); router.get('/hit/today/:category', require('./routes/universities/hit/today'));
// 上海科技大学 // 上海科技大学
router.get('/shanghaitech/activity', require('./routes/universities/shanghaitech/activity'));
router.get('/shanghaitech/sist/activity', require('./routes/universities/shanghaitech/sist/activity')); router.get('/shanghaitech/sist/activity', require('./routes/universities/shanghaitech/sist/activity'));
// 上海交通大学 // 上海交通大学

View File

@@ -0,0 +1,35 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const link = 'http://www.shanghaitech.edu.cn/qb/list.htm';
const response = await got({ method: 'get', url: link });
const $ = cheerio.load(response.data);
const list = $('ul.news_list.clearfix li')
.map((i, e) => ({
link: `http://www.shanghaitech.edu.cn` + $(e).find('a').attr('href'),
title: $(e).find('a').text(),
pubDate: $(e).find('div.news_time').attr('data-time'),
}))
.get();
ctx.state.data = {
title: '上海科技大学 - 活动',
link: link,
item: await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
if (item.link.indexOf('_redirect?') === -1) {
const detailResponse = await got({ method: 'get', url: item.link });
const content = cheerio.load(detailResponse.data);
item.description = content('div.wp_articlecontent').html();
}
return item;
})
)
),
};
};