增加:南京航空航天大学计算机学院学术讲座 (#1254)

This commit is contained in:
Chenyang Shi 2018-12-10 14:19:27 +08:00 committed by DIYgod
parent eabe3ff173
commit 20650ca496
3 changed files with 67 additions and 0 deletions

View File

@ -1268,6 +1268,8 @@ GitHub 官方也提供了一些 RSS:
</route>
<route name="计算机科学与技术学院学术活动" author="LogicJake" example="/nuaa/cs/academic" path="/universities/nuaa/cs/academic"/>
### 哈尔滨工业大学
<route name="哈尔滨工业大学教务处通知公告" author="lty96117" example="/hit/jwc" path="/universities/hit/jwc"/>

View File

@ -540,6 +540,7 @@ router.get('/seu/yzb/:type', require('./routes/universities/seu/yzb'));
// 南京航空航天大学
router.get('/nuaa/jwc/:type?', require('./routes/universities/nuaa/jwc/jwc'));
router.get('/nuaa/cs/academic', require('./routes/universities/nuaa/cs/academic'));
// 哈尔滨工业大学
router.get('/hit/jwc', require('./routes/universities/hit/jwc'));

View File

@ -0,0 +1,64 @@
const axios = require('../../../../utils/axios');
const cheerio = require('cheerio');
const url = require('url');
const host = 'http://cs.nuaa.edu.cn/';
module.exports = async (ctx) => {
const link = url.resolve(host, '1975/list.htm');
const response = await axios.get(link);
const $ = cheerio.load(response.data);
const list = $('tr.section')
.slice(0, 10)
.map(function() {
const info = {
title: $(this)
.find('td:nth-child(2) a')
.attr('title'),
link: $(this)
.find('td:nth-child(2) a')
.attr('href'),
date: $(this)
.find('td:nth-child(3)')
.text(),
};
return info;
})
.get();
const out = await Promise.all(
list.map(async (info) => {
const title = info.title;
const date = info.date;
const itemUrl = url.resolve(host, info.link);
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: title,
link: itemUrl,
description: $('.wp_articlecontent')
.html()
.replace(/src="\//g, `src="${url.resolve(host, '.')}`)
.trim(),
pubDate: new Date(date),
};
ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60);
return Promise.resolve(single);
})
);
ctx.state.data = {
title: '南航计算机科学与技术学院学术讲座',
link: link,
description: '南航计算机科学与技术学院学术讲座RSS',
item: out,
};
};