diff --git a/docs/other.md b/docs/other.md index 0e88ef3532..827fb9c758 100644 --- a/docs/other.md +++ b/docs/other.md @@ -427,6 +427,18 @@ type 为 all 时,category 参数不支持 cost 和 free +## 四川省科学技术厅 + +### 四川省科学技术厅-公示公告 + + + +| 通知 | 公示公告 | +| ---- | -------- | +| tz | gs | + + + ## 搜狗 ### 搜狗特色 LOGO diff --git a/lib/router.js b/lib/router.js index 1051724506..c215dd18d8 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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; diff --git a/lib/routes/sckjt/news.js b/lib/routes/sckjt/news.js new file mode 100644 index 0000000000..30be3322a3 --- /dev/null +++ b/lib/routes/sckjt/news.js @@ -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(), + }; +};