From c0ec11a177647b6a44856f3abb202d4f3f3be39e Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Fri, 8 May 2020 11:30:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E4=B8=AD=E5=9B=BD=E4=BA=BA?= =?UTF-8?q?=E4=BA=8B=E8=80=83=E8=AF=95=E7=BD=91=E9=80=9A=E7=9F=A5=E5=85=AC?= =?UTF-8?q?=E5=91=8A=20(#4691)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/study.md | 6 ++++++ lib/router.js | 3 +++ lib/routes/cpta/notice.js | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 lib/routes/cpta/notice.js diff --git a/docs/study.md b/docs/study.md index 1a328c98f4..1daf9aab3c 100644 --- a/docs/study.md +++ b/docs/study.md @@ -281,3 +281,9 @@ pageClass: routes ### 最新 + +## 中国人事考试网 + +### 通知公告 + + diff --git a/lib/router.js b/lib/router.js index 92ddfeea50..78dc92b9fc 100755 --- a/lib/router.js +++ b/lib/router.js @@ -2644,6 +2644,9 @@ router.get('/slu/csggxy/:id', require('./routes/universities/slu/csggxy')); router.get('/ruby-china/topics/:type?', require('./routes/ruby-china/topics')); router.get('/ruby-china/jobs', require('./routes/ruby-china/jobs')); +// 中国人事考试网 +router.get('/cpta/notice', require('./routes/cpta/notice')); + // 广告网 router.get('/adquan/:type?', require('./routes/adquan/index')); diff --git a/lib/routes/cpta/notice.js b/lib/routes/cpta/notice.js new file mode 100644 index 0000000000..86aeeedce8 --- /dev/null +++ b/lib/routes/cpta/notice.js @@ -0,0 +1,37 @@ +const url = require('url'); +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); + +module.exports = async (ctx) => { + const link = `http://www.cpta.com.cn/GB/360339/index.html`; + const response = await got({ method: 'get', url: link, responseType: 'buffer' }); + + const $ = cheerio.load(iconv.decode(response.data, 'gbk')); + const list = $('ul.list_14 li') + .map((_, item) => { + item = $(item).find('a'); + return { + title: item.text(), + link: url.resolve(`http://www.cpta.com.cn/`, item.attr('href')), + }; + }) + .get(); + + ctx.state.data = { + title: '中国人事考试网 - 通知公告', + link: link, + item: await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ method: 'get', url: item.link, responseType: 'buffer' }); + const content = cheerio.load(iconv.decode(detailResponse.data, 'gbk')); + item.description = content('div.text').html(); + item.pubDate = new Date(content('#p_publishtime').text().replace(/[年|月]/g, '-').replace(/日/g, ' ') + ' GMT+8').toUTCString(); + return item; + }) + ) + ), + }; +};