feat(route): add 厦门大学航院 (#8137)

* feat(route): add 厦门大学航院

* Simplify the code

* Fix the problem of tryGet
This commit is contained in:
蒋晨辉
2021-09-03 17:28:33 +08:00
committed by GitHub
parent ea21cfdd28
commit 88514fa259
3 changed files with 79 additions and 0 deletions

View File

@@ -653,6 +653,19 @@ xskb1 对应 <http://www.auto.uestc.edu.cn/index/xskb1.htm>
| -------- | -------- |
| jxtz | zjjz |
## 厦门大学
## 航空航天学院
<Route author="jch12138" example="/xmu/aero/yjsjw" path="/xmu/aero/:type" :paramsDesc="['分类见下表']"/>
| 通知公告 | 本科生教务 | 研究生教务 |
| :--------: | :--------: | :--------: |
| tzgg | bksjw | yjsjw|
</Route>
## 复旦大学继续教育学院
### 成人夜大通知公告

View File

@@ -945,6 +945,9 @@ router.get('/lyu/news/:type', lazyloadRouteHandler('./routes/universities/lyu/ne
// 福州大学
router.get('/fzu/:type', lazyloadRouteHandler('./routes/universities/fzu/news'));
// 厦门大学
router.get('/xmu/aero/:type', lazyloadRouteHandler('./routes/universities/xmu/aero'));
// ifanr
router.get('/ifanr/:channel?', lazyloadRouteHandler('./routes/ifanr/index'));

View File

@@ -0,0 +1,63 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const host = 'https://aerospace.xmu.edu.cn';
const urlMap = {
tzgg: '/xydt/tzgg.htm',
bksjw: '/jwxx/bksjw.htm',
yjsjw: '/jwxx/yjsjw.htm'
};
const titleMap = {
tzgg: '通知公告',
bksjw: '本科生教务',
yjsjw: '研究生教务'
};
module.exports = async (ctx) => {
const type = ctx.params.type || '';
const response = await got({
method: 'get',
url: host + urlMap[type],
});
const data = response.data;
const $ = cheerio.load(data, { decodeEntities: false });
const list = $('body > div.centers > div.other_right > ul > li')
.map((index, item) => {
item = $(item);
const $a = item.find('a');
return {
title: $a.attr('title'),
link: host + $a.attr('href').slice(2,)
};
})
.get();
const result = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data, { decodeEntities: false });
item.description = content('#vsb_content > div').html();
const date = content('body > div.centers > div.other_right > form > div > div.news-info.clearfix > span:nth-child(2)').text();
item.pubDate = parseDate(date, '发布时间YYYY年MM月DD日');
return item;
})
)
);
ctx.state.data = {
title: titleMap[type],
link: host,
item: result,
};
};