From 713253bed4691cf446fffcf02f10f85895bdf3ea Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sat, 27 Nov 2021 15:53:36 +0800 Subject: [PATCH] =?UTF-8?q?fix(route):=20=E6=B7=B1=E5=9C=B3=E8=AF=81?= =?UTF-8?q?=E5=88=B8=E4=BA=A4=E6=98=93=E6=89=80=E6=9C=80=E6=96=B0=E8=A7=84?= =?UTF-8?q?=E5=88=99=20(#8284)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/router.js | 1 - lib/routes/szse/rule.js | 45 ---------------------------------- lib/v2/szse/maintainer.js | 3 +++ lib/v2/szse/radar.js | 13 ++++++++++ lib/v2/szse/router.js | 3 +++ lib/v2/szse/rule.js | 51 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 70 insertions(+), 46 deletions(-) delete mode 100644 lib/routes/szse/rule.js create mode 100644 lib/v2/szse/maintainer.js create mode 100644 lib/v2/szse/radar.js create mode 100644 lib/v2/szse/router.js create mode 100644 lib/v2/szse/rule.js diff --git a/lib/router.js b/lib/router.js index be48680bcc..365cc0de41 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2166,7 +2166,6 @@ router.get('/sse/disclosure/:query?', lazyloadRouteHandler('./routes/sse/disclos // 深圳证券交易所 router.get('/szse/notice', lazyloadRouteHandler('./routes/szse/notice')); router.get('/szse/inquire/:type', lazyloadRouteHandler('./routes/szse/inquire')); -router.get('/szse/rule', lazyloadRouteHandler('./routes/szse/rule')); router.get('/szse/projectdynamic/:type?/:stage?/:status?', lazyloadRouteHandler('./routes/szse/projectdynamic')); // 前端艺术家每日整理&&飞冰早报 diff --git a/lib/routes/szse/rule.js b/lib/routes/szse/rule.js deleted file mode 100644 index 50b8482219..0000000000 --- a/lib/routes/szse/rule.js +++ /dev/null @@ -1,45 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); - -module.exports = async (ctx) => { - const currentUrl = `http://www.szse.cn/lawrules/rule/new/`; - const response = await got({ - method: 'get', - url: currentUrl, - }); - const $ = cheerio.load(response.data); - const list = $('ul.newslist li') - .slice(0, 10) - .map((_, item) => { - item = $(item); - const s = item.find('script').html(); - return { - title: s.match(/var curTitle ='(.*?)';/)[1], - link: `http://www.szse.cn/lawrules/rule${s.match(/var curHref = '..(.*?)';/)[1]}`, - pubDate: new Date(item.find('span.time').text().trim()).toUTCString(), - }; - }) - .get(); - - const items = await Promise.all( - list.map((item) => - ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - const content = cheerio.load(detailResponse.data); - - item.description = content('#desContent').html(); - - return item; - }) - ) - ); - - ctx.state.data = { - title: '深圳证券交易所 - 最新规则', - link: currentUrl, - item: items, - }; -}; diff --git a/lib/v2/szse/maintainer.js b/lib/v2/szse/maintainer.js new file mode 100644 index 0000000000..d1e8166866 --- /dev/null +++ b/lib/v2/szse/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/rule': ['nczitzk'], +}; diff --git a/lib/v2/szse/radar.js b/lib/v2/szse/radar.js new file mode 100644 index 0000000000..d9099c4f1c --- /dev/null +++ b/lib/v2/szse/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'szse.cn': { + _name: '深圳证券交易所', + '.': [ + { + title: '最新规则', + docs: 'https://docs.rsshub.app/other.html#shen-zhen-zheng-quan-jiao-yi-suo-zui-xin-gui-ze', + source: ['/lawrules/rule/new', '/'], + target: '/szse/rule', + }, + ], + }, +}; diff --git a/lib/v2/szse/router.js b/lib/v2/szse/router.js new file mode 100644 index 0000000000..1fc4370589 --- /dev/null +++ b/lib/v2/szse/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/rule', require('./rule')); +}; diff --git a/lib/v2/szse/rule.js b/lib/v2/szse/rule.js new file mode 100644 index 0000000000..baf98df3a9 --- /dev/null +++ b/lib/v2/szse/rule.js @@ -0,0 +1,51 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const rootUrl = 'http://www.szse.cn'; + const currentUrl = `${rootUrl}/api/search/content`; + + const response = await got({ + method: 'post', + url: currentUrl, + form: { + keyword: '', + time: 0, + range: 'title', + 'channelCode[]': 'szserulesAllRulesBuss', + currentPage: 1, + pageSize: 30, + scope: 0, + }, + }); + + const list = response.data.data.map((item) => ({ + title: item.doctitle, + link: item.docpuburl, + pubDate: parseDate(item.docpubtime), + })); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + item.description = content('#desContent').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: '最新规则 - 深圳证券交易所', + link: `${rootUrl}/lawrules/rule/new`, + item: items, + }; +};