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, + }; +};