feat: add 四川省科学技术厅 (#4284)

This commit is contained in:
Xiaolei Liu
2020-03-24 10:41:06 +08:00
committed by GitHub
parent af20226677
commit ef27e7ca8b
3 changed files with 61 additions and 0 deletions

View File

@@ -427,6 +427,18 @@ type 为 all 时category 参数不支持 cost 和 free
<Route author="Jeason0228" example="/szse/inquire/navall" path="/szse/inquire/:type" :paramsDesc="['tab选项,navall为全部,nav1为主板,nav2,为中小企业板,nav3位创业板']"/>
## 四川省科学技术厅
### 四川省科学技术厅-公示公告
<Route author="Cubernet" example="/sckjt/news" path="/sckjt/news/:type?" :paramsDesc="['默认为`tz`']">
| 通知 | 公示公告 |
| ---- | -------- |
| tz | gs |
</Route>
## 搜狗
### 搜狗特色 LOGO

View File

@@ -2409,4 +2409,7 @@ router.get('/hubu/news/:type', require('./routes/universities/hubu/news'));
// 大连海事大学
router.get('/dlmu/news/:type', require('./routes/universities/dlmu/news'));
// 四川省科学技术厅
router.get('/sckjt/news/:type?', require('./routes/sckjt/news'));
module.exports = router;

46
lib/routes/sckjt/news.js Normal file
View File

@@ -0,0 +1,46 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const baseUrl = 'http://kjt.sc.gov.cn';
const dateRegex = /\((\d{4})-(\d{2})-(\d{2})\)/;
const map = {
tz: '/tz/index.jhtml',
gs: '/gs/index.jhtml',
};
module.exports = async (ctx) => {
const type = ctx.params.type || 'tz';
const response = await got({
method: 'get',
url: baseUrl + map[type],
});
const data = response.data;
const $ = cheerio.load(data);
ctx.state.data = {
title: '四川省科学技术厅',
link: baseUrl,
item: $('div[class="news_middle_top"]')
.next('div')
.children('h2')
.slice(0, 15)
.map((_, elem) => ({
link:
baseUrl +
$(elem)
.children('a')
.attr('href'),
title: $(elem)
.children('a')
.text(),
pubDate: new Date(
$(elem)
.children('span')
.text()
.replace(dateRegex, '$1-$2-$3')
).toUTCString(),
}))
.get(),
};
};