feat: add 四川职业技术学院学院公告 (#5304)

This commit is contained in:
Ethan Shen
2020-08-01 16:59:29 +01:00
committed by GitHub
parent 7326c71386
commit 7a187cb264
3 changed files with 55 additions and 0 deletions
+6
View File
@@ -1409,6 +1409,12 @@ type 列表:
<Route author="talenHuang" example="/sctu/jwc/13/645" path="/sctu/jwc/context/:type/:id" :paramsDesc="['通知类型','文章id']"/>
## 四川职业技术学院
### 学院公告
<Route author="nczitzk" example="/scvtc/xygg" path="/scvtc/xygg" />
## 天津大学
### 天津大学教务处
+3
View File
@@ -3040,6 +3040,9 @@ router.get('/hfut/tzgg', require('./routes/universities/hfut/tzgg'));
// Darwin Awards
router.get('/darwinawards/all', require('./routes/darwinawards/articles'));
// 四川职业技术学院
router.get('/scvtc/xygg', require('./routes/universities/scvtc/xygg'));
// OneJAV
router.get('/onejav/:type/:key?', require('./routes/onejav/one'));
+46
View File
@@ -0,0 +1,46 @@
const url = require('url');
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const currentUrl = 'http://scvtc.edu.cn/ggfw1/xygg.htm';
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('div.list_l div ul li')
.map((_, item) => {
item = $(item);
const a = item.find('a[title]');
return {
title: a.text(),
link: url.resolve(currentUrl, a.attr('href')),
pubDate: new Date(item.find('span.c43271_date').text().split('&nbsp;')[0].trim()).toUTCString(),
};
})
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.description = content('#vsb_content').html();
return item;
})
)
);
ctx.state.data = {
title: '四川职业技术学院 - 学院公告',
link: currentUrl,
item: items,
};
};