From e5d872e58482e4aa3957fa24add47dae8eb1bb07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B0=E7=B4=85=E8=8C=B6?= Date: Wed, 12 May 2021 07:19:33 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=B9=BF=E4=B8=9C?= =?UTF-8?q?=E7=9C=81=E6=95=99=E8=82=B2=E8=80=83=E8=AF=95=E9=99=A2=20(#7518?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/government.md | 10 ++++++ lib/router.js | 4 +++ lib/routes/gov/guangdong/eea.js | 60 +++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 lib/routes/gov/guangdong/eea.js diff --git a/docs/government.md b/docs/government.md index 6482a2a0d2bf75..31543faaa20df6 100644 --- a/docs/government.md +++ b/docs/government.md @@ -28,6 +28,16 @@ pageClass: routes +### 广东省教育考试院 + + + +| 考试招生 | 社会考试 | 招考公示 | 报考指南 | 要闻动态 | 公开专栏 | 政策文件 | 政策解读 | +| :------: | :------: | :------: | :------: | :------: | :------: | :------: | :------: | +| kszs | shks | zkgs | bkzn | news | gkzl | zcwj | zcjd | + + + ### 广东省深圳市人民政府 diff --git a/lib/router.js b/lib/router.js index 777ea2b90fd76f..69a373e9a1273e 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1349,6 +1349,10 @@ router.get('/gov/beijing/bjeea/:type', require('./routes/gov/beijing/eea')); // 广东省教育厅 router.get('/gov/guangdong/edu/:caty', require('./routes/gov/guangdong/edu')); + +// 广东省教育考试院 +router.get('/gov/guangdong/eea/:caty', require('./routes/gov/guangdong/eea')); + // 广东省深圳市 router.get('/gov/shenzhen/xxgk/zfxxgj/:caty', require('./routes/gov/shenzhen/xxgk/zfxxgj')); diff --git a/lib/routes/gov/guangdong/eea.js b/lib/routes/gov/guangdong/eea.js new file mode 100644 index 00000000000000..92afc69544f859 --- /dev/null +++ b/lib/routes/gov/guangdong/eea.js @@ -0,0 +1,60 @@ +const url = require('url'); +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const timezone = require('@/utils/timezone'); +const parseDate = require('@/utils/parse-date'); +const rootUrl = 'http://eea.gd.gov.cn/'; + +const config = { + kszs: { link: '/bmbk/kszs/', title: '考试招生' }, + shks: { link: '/shks/', title: '社会考试' }, + zkgs: { link: '/zwgk_zkgs/', title: '招考公示' }, + bkzn: { link: '/bmbk/bkzn/', title: '报考指南' }, + ywdt: { link: '/news/', title: '要闻动态' }, + gkzl: { link: '/zwgk/gkzl/', title: '公开专栏' }, + zcwj: { link: '/zwgk/zwwj/', title: '政策文件' }, + zcjd: { link: '/zcjd/', title: '政策解读' }, +}; + +module.exports = async (ctx) => { + const cfg = config[ctx.params.caty]; + if (!cfg) { + throw Error('Bad category. See docs'); + } + + const currentUrl = url.resolve(rootUrl, cfg.link); + const response = await got({ method: 'get', url: currentUrl }); + + const $ = cheerio.load(response.data); + const list = $('div.main>div.content>ul>li') + .map((_, item) => { + item = $(item).find('a'); + return { + title: item.text(), + link: item.attr('href'), + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + if (item.link.includes('weixin.qq.com')) { + return item; + } + const detailResponse = await got({ method: 'get', url: item.link }); + const content = cheerio.load(detailResponse.data); + item.description = content('div.article').html(); + item.pubDate = timezone(parseDate(content('span.time').text()), +8); + return item; + }) + ) + ); + + ctx.state.data = { + title: '广东省教育考试院 - ' + cfg.title, + link: currentUrl, + item: items, + }; +};