From d9ea1729d1841103063c41150fbd3f1c58d814c8 Mon Sep 17 00:00:00 2001 From: 32fsd <34313916+h2ws@users.noreply.github.com> Date: Tue, 22 Feb 2022 23:36:02 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E4=B8=8A=E6=B5=B7?= =?UTF-8?q?=E6=95=99=E8=82=B2=E8=80=83=E8=AF=95=E9=99=A2=E8=87=AA=E5=AD=A6?= =?UTF-8?q?=E8=80=83=E8=AF=95=E9=80=9A=E7=9F=A5=E5=85=AC=E5=91=8A=20(#7863?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 上海教育考试院自学考试通知公告 * refactor: migrate to v2 Co-authored-by: oyydd Co-authored-by: TonyRL --- docs/other.md | 7 ----- docs/study.md | 12 ++++++++ lib/router.js | 3 ++ lib/v2/shmeea/maintainer.js | 1 + lib/v2/shmeea/radar.js | 6 ++++ lib/v2/shmeea/router.js | 3 +- lib/v2/shmeea/self-study.js | 61 +++++++++++++++++++++++++++++++++++++ 7 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 lib/v2/shmeea/self-study.js diff --git a/docs/other.md b/docs/other.md index ffbf40c629..f815b74cda 100644 --- a/docs/other.md +++ b/docs/other.md @@ -747,13 +747,6 @@ type 为 all 时,category 参数不支持 cost 和 free -## 上海市教育考试院 - -### 消息速递 - -官方网址: - - ## 上海证券交易所 ### 上市公司信息最新公告披露 diff --git a/docs/study.md b/docs/study.md index bf1a894f8e..ce58d8aed4 100644 --- a/docs/study.md +++ b/docs/study.md @@ -278,6 +278,18 @@ path="/ctfhub/upcoming/:limit?" +## 上海市教育考试院 + +### 消息速递 + +官方网址: + + + +### 自学考试通知公告 + + + ## 思维导图社区 ### 热门导图 diff --git a/lib/router.js b/lib/router.js index addbec5e23..10a242367c 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3605,6 +3605,9 @@ router.get('/esquirehk/tag/:id', lazyloadRouteHandler('./routes/esquirehk/tag')) // 国家普通话测试 杭州市 router.get('/putonghua', lazyloadRouteHandler('./routes/putonghua/hangzhou')); +// 国家自学考试 上海市 migrated to v2 /shmeea/self-study +// router.get('/self-study/shanghai', require('./routes/self-study/shanghai')); + // 有道云笔记 router.get('/youdao/xueba', lazyloadRouteHandler('./routes/youdao/xueba')); router.get('/youdao/latest', lazyloadRouteHandler('./routes/youdao/latest')); diff --git a/lib/v2/shmeea/maintainer.js b/lib/v2/shmeea/maintainer.js index 4e3ee73d6b..000328f180 100644 --- a/lib/v2/shmeea/maintainer.js +++ b/lib/v2/shmeea/maintainer.js @@ -1,3 +1,4 @@ module.exports = { '/': ['jialinghui'], + '/self-study': ['h2ws'], }; diff --git a/lib/v2/shmeea/radar.js b/lib/v2/shmeea/radar.js index 016d5b2d38..6bf833eb16 100644 --- a/lib/v2/shmeea/radar.js +++ b/lib/v2/shmeea/radar.js @@ -8,6 +8,12 @@ module.exports = { source: ['/'], target: '/shmeea', }, + { + title: '自学考试通知公告', + docs: 'https://docs.rsshub.app/other.html#shang-hai-shi-jiao-yu-kao-shi-yuan', + source: ['/page/04000/index.html', '/'], + target: '/shmeea/self-study', + }, ], }, }; diff --git a/lib/v2/shmeea/router.js b/lib/v2/shmeea/router.js index 437937a54e..b864ea159b 100644 --- a/lib/v2/shmeea/router.js +++ b/lib/v2/shmeea/router.js @@ -1,3 +1,4 @@ module.exports = function (router) { - router.get('', require('./index')); + router.get('/', require('./index')); + router.get('/self-study', require('./self-study')); }; diff --git a/lib/v2/shmeea/self-study.js b/lib/v2/shmeea/self-study.js new file mode 100644 index 0000000000..ec1118b867 --- /dev/null +++ b/lib/v2/shmeea/self-study.js @@ -0,0 +1,61 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +async function load_detail(list, cache) { + return await Promise.all( + list.map(async (item) => { + const notice_item = cheerio.load(item); + const href = notice_item('a').attr('href'); + const url = 'http://www.shmeea.edu.cn' + href; + if (href[0] !== '/') { + return { + title: notice_item('a').attr('title'), + description: `附件`, + link: href, + }; + } + return await cache.tryGet(url, async () => { + const detail_response = await got({ + method: 'get', + url, + headers: { + Referer: 'http://www.shmeea.edu.cn/page/04000/index.html', + Host: 'www.shmeea.edu.cn', + }, + }); + const detail = cheerio.load(detail_response.data); + return { + title: notice_item('a').attr('title'), + description: detail('.Article_content').html(), + link: url, + pubDate: timezone(parseDate(detail('.PBtime').text(), 'YYYY-MM-DD HH:mm:ss'), +8), + }; + }); + }) + ); +} + +module.exports = async (ctx) => { + const response = await got({ + method: 'get', + url: 'http://www.shmeea.edu.cn/page/04000/index.html', + headers: { + Host: 'www.shmeea.edu.cn', + }, + }); + + const data = response.data; + + const $ = cheerio.load(data); + const list = $('#main > div.container > div > div.span9 > div.page-he > div > ul > li').get(); + + const detail = await load_detail(list, ctx.cache); + + ctx.state.data = { + title: '上海自学考试 - 通知公告', + link: 'http://www.shmeea.edu.cn/page/04000/index.html', + item: detail, + }; +};