feat: add njtech jwc (#2682)

* feat: add njtech jwc

* style: format code style
This commit is contained in:
TrumanGu
2019-07-25 11:27:58 +08:00
committed by DIYgod
parent 897e567523
commit 058a5ee5f3
3 changed files with 65 additions and 0 deletions

View File

@@ -954,3 +954,9 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet
### 数据科学与计算机学院动态
<Route author="MegrezZhu" example="/sysu/sdcs" path="/sysu/sdcs" />
## 南京工业大学
### 南京工业大学教务处
<Route author="TrumanGu" example="/njtech/jwc" path="/njtech/jwc" />

View File

@@ -534,6 +534,9 @@ router.get('/seu/radio/academic', require('./routes/universities/seu/radio/acade
router.get('/seu/yzb/:type', require('./routes/universities/seu/yzb'));
router.get('/seu/cse/:type?', require('./routes/universities/seu/cse'));
// 南京工业大学
router.get('/njtech/jwc', require('./routes/universities/njtech/jwc'));
// 南京航空航天大学
router.get('/nuaa/jwc/:type?', require('./routes/universities/nuaa/jwc/jwc'));
router.get('/nuaa/cs/:type?', require('./routes/universities/nuaa/cs/index'));

View File

@@ -0,0 +1,56 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const host = 'http://jwb.njtech.edu.cn';
const link = host + '/index/tzgg.htm';
module.exports = async (ctx) => {
const response = await got({
method: 'get',
url: link,
headers: {
Referer: host,
},
});
const $ = cheerio.load(response.data);
const urlList = $('#mainRight li a')
.get()
.map(
(i) =>
host +
$(i)
.attr('href')
.replace('..', '')
);
const out = await Promise.all(
urlList.map(async (itemUrl) => {
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await got.get(itemUrl);
const $ = cheerio.load(response.data);
const single = {
title: $('#mainRight .title').text(),
link: itemUrl,
description: $('#vsb_content').html(),
pubDate: $('.time')
.text()
.match(/(\d{4}-\d{2})-\d{2}/)[0],
};
ctx.cache.set(itemUrl, JSON.stringify(single));
return Promise.resolve(single);
})
);
const info = '教务公告';
ctx.state.data = {
title: '南京工业大学教务处 - ' + info,
link,
item: out,
};
};