feat(route): 澳門特別行政區政府各公共部門獎助貸學金服務平台 (#7547)

This commit is contained in:
KeiLongW
2021-06-14 10:14:46 -07:00
committed by GitHub
parent c2d63704ee
commit aedc536fcb
3 changed files with 62 additions and 0 deletions
+12
View File
@@ -973,3 +973,15 @@ type 为 all 时,category 参数不支持 cost 和 free
### はてな匿名ダイアリー - 人気記事アーカイブ
<Route author="masakichi" example="/hatena/anonymous_diary/archive" path="/hatena/anonymous_diary/archive"/>
### 澳門特別行政區政府各公共部門獎助貸學金服務平台
官方網址:<https://www.bolsas.gov.mo/>
<Route author="KeiLongW" example="/macau-bolsas" path="/macau-bolsas/:lang?" :paramsDesc="['語言']" >
| 中文 | 葡文 |
| ---- | ---- |
| ch | pt |
</Route>
+3
View File
@@ -4103,4 +4103,7 @@ router.get('/hainanu/ssszs', require('./routes/hainanu/ssszs'));
// 游戏年轮
router.get('/bibgame/:category?/:type?', require('./routes/bibgame/category'));
// 澳門特別行政區政府各公共部門獎助貸學金服務平台
router.get('/macau-bolsas/:lang?', require('./routes/macau-bolsas/index'));
module.exports = router;
+47
View File
@@ -0,0 +1,47 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const lang = ctx.params.lang;
const url = `https://www.bolsas.gov.mo/${lang === 'pt' ? lang : ''}`;
const response = await got({
method: 'get',
url: url,
});
const $Wrapper = cheerio.load(response.data);
const liItems = $Wrapper('ul.news-list li');
const items = await Promise.all(
liItems &&
liItems
.map(async (_, item) => {
const $item = $Wrapper(item);
const $newsItem = $item.find('.news-item');
const bureau = $newsItem.find('.label').text();
const title = $newsItem.find('.title').text();
const link = $newsItem.find('.title').attr('href');
const pubDate = new Date($item.find('.date').text() + 'T00:00:00+0800');
const description = await ctx.cache.tryGet(link, async () => {
const response = await got({
method: 'get',
url: link,
});
const $ = cheerio.load(response.data);
return $('.news-content').html();
});
return Promise.resolve({
title: `[${bureau}] ${title}`,
link,
description,
pubDate,
});
})
.get()
);
ctx.state.data = {
title: '澳門特別行政區政府各公共部門獎助貸學金服務平台',
link: url,
description: '澳門特別行政區政府各公共部門獎助貸學金服務平台',
item: items,
};
};