From 01e2e15cf669b73d1b46955da491e5dbc1d40e70 Mon Sep 17 00:00:00 2001 From: ChaosTong Date: Mon, 30 Nov 2020 02:45:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E6=9D=AD=E5=B7=9E=E5=B8=82?= =?UTF-8?q?=E5=9B=BD=E5=AE=B6=E6=99=AE=E9=80=9A=E8=AF=9D=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=BD=91=E6=8A=A5=E4=BF=A1=E6=81=AF=20(#6196)?= 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/putonghua/hangzhou.js | 45 ++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 lib/routes/putonghua/hangzhou.js diff --git a/docs/study.md b/docs/study.md index bc560a9cf9..a7a69a6ace 100644 --- a/docs/study.md +++ b/docs/study.md @@ -396,3 +396,9 @@ pageClass: routes ### 通知公告 + +## 杭州市国家普通话测试网报信息 + +### 考试信息 + + diff --git a/lib/router.js b/lib/router.js index 100043b51b..af1d796342 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3510,6 +3510,9 @@ router.get('/uisdc/news', require('./routes/uisdc/news')); router.get('/uisdc/zt/:title?', require('./routes/uisdc/zt')); router.get('/uisdc/topic/:title?/:sort?', require('./routes/uisdc/topic')); +// 国家普通话测试 杭州市 +router.get('/putonghua', require('./routes/putonghua/hangzhou')); + // 有道云笔记 router.get('/youdao/xueba', require('./routes/youdao/xueba')); router.get('/youdao/latest', require('./routes/youdao/latest')); diff --git a/lib/routes/putonghua/hangzhou.js b/lib/routes/putonghua/hangzhou.js new file mode 100644 index 0000000000..5dc0326b53 --- /dev/null +++ b/lib/routes/putonghua/hangzhou.js @@ -0,0 +1,45 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const rootUrl = 'http://cltt.51hzks.cn/queryExamInfo'; + const response = await got({ + method: 'get', + url: rootUrl, + }); + + const $ = cheerio.load(response.data); + + const title = []; + const items = []; + $('.pth_smrtable') + .find('th') + .each((i, e) => { + const titleStr = $(e).text().replace(/\n/g, '').replace(/\t/g, ''); + title.push(titleStr); + }); + + $('.pth_smrtable') + .find('tr') + .slice(1) + .each((i, e) => { + let examInfo = ''; + $(e) + .find('td') + .each((i, e) => { + const titleStr = $(e).text().trim().replace(/\n/g, '').replace(/\t/g, ''); + examInfo += `${title[i]}: ${titleStr} `; + }); + items.push({ title: '近期杭州市普通话测试信息', description: examInfo }); + }); + + if (!(items.count > 0)) { + items.push({ title: '近期杭州市普通话测试信息', description: '近期暂无考试' }); + } + + ctx.state.data = { + title: `近期杭州市普通话测试网报时间及考试地点公布`, + link: rootUrl, + item: items, + }; +};