From 1474949bee04b14b938ff5f07dfa7eb3bd441be9 Mon Sep 17 00:00:00 2001 From: Tony Date: Thu, 2 Mar 2023 00:44:46 +0800 Subject: [PATCH] fix(route): csrc (#11996) --- docs/government.md | 14 +++-- lib/router.js | 6 +-- lib/routes/csrc/auditstatus.js | 61 --------------------- lib/routes/csrc/fashenwei.js | 42 --------------- lib/routes/csrc/news.js | 45 ---------------- lib/v2/gov/csrc/auditstatus.js | 54 +++++++++++++++++++ lib/v2/gov/csrc/news.js | 69 ++++++++++++++++++++++++ lib/v2/gov/csrc/templates/attachment.art | 3 ++ lib/v2/gov/maintainer.js | 2 + lib/v2/gov/radar.js | 19 +++++++ lib/v2/gov/router.js | 2 + 11 files changed, 161 insertions(+), 156 deletions(-) delete mode 100644 lib/routes/csrc/auditstatus.js delete mode 100644 lib/routes/csrc/fashenwei.js delete mode 100644 lib/routes/csrc/news.js create mode 100644 lib/v2/gov/csrc/auditstatus.js create mode 100644 lib/v2/gov/csrc/news.js create mode 100644 lib/v2/gov/csrc/templates/attachment.art diff --git a/docs/government.md b/docs/government.md index e39c49b8a..ba4d05236 100644 --- a/docs/government.md +++ b/docs/government.md @@ -1216,17 +1216,21 @@ pageClass: routes ## 中国证券监督管理委员会 -### 发审委公告 +### 通用 - + -### 证监会消息 +::: tip 提示 +路径处填写对应页面 URL 中 `http://www.csrc.gov.cn/csrc/` 后的字段。下面是一个例子。 - +若订阅 [证监会要闻](http://www.csrc.gov.cn/csrc/c100028/common_xq_list.shtml) 则将对应页面 URL 中 `http://www.csrc.gov.cn/csrc/` 后的字段 `c100028/common_xq_list.shtml` 作为路径填入。此时路由为 [`/gov/csrc/news/c100028/common_xq_list.shtml`](https://rsshub.app/gov/csrc/news/c100028/common_xq_list.shtml) +::: + + ### 申请事项进度 - + ## 中国政府网 diff --git a/lib/router.js b/lib/router.js index 56168c4e0..769135f2f 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1754,9 +1754,9 @@ router.get('/8btc/news/flash', lazyloadRouteHandler('./routes/8btc/news/flash')) router.get('/vuevideo/:userid', lazyloadRouteHandler('./routes/vuevideo/user')); // 证监会 -router.get('/csrc/news/:suffix?', lazyloadRouteHandler('./routes/csrc/news')); -router.get('/csrc/fashenwei', lazyloadRouteHandler('./routes/csrc/fashenwei')); -router.get('/csrc/auditstatus/:apply_id', lazyloadRouteHandler('./routes/csrc/auditstatus')); +// router.get('/csrc/news/:suffix?', lazyloadRouteHandler('./routes/csrc/news')); +// router.get('/csrc/fashenwei', lazyloadRouteHandler('./routes/csrc/fashenwei')); +// router.get('/csrc/auditstatus/:apply_id', lazyloadRouteHandler('./routes/csrc/auditstatus')); // LWN.net Alerts router.get('/lwn/alerts/:distributor', lazyloadRouteHandler('./routes/lwn/alerts')); diff --git a/lib/routes/csrc/auditstatus.js b/lib/routes/csrc/auditstatus.js deleted file mode 100644 index b11563990..000000000 --- a/lib/routes/csrc/auditstatus.js +++ /dev/null @@ -1,61 +0,0 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); - -module.exports = async (ctx) => { - const apply_id = ctx.params.apply_id; - const userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1'; - const item_url = `https://neris.csrc.gov.cn/alappl/home1/onlinealog?appMatrCde=${apply_id}`; - const url = 'https://neris.csrc.gov.cn/alappl/home1/onlinealog.do'; - const res = await got({ - // method: 'get', - method: 'post', - url, - headers: { - 'User-Agent': userAgent, - }, - form: { - appMatrCde: apply_id, - pageNo: 1, - pageSize: 10, - }, - rejectUnauthorized: false, - }); - const $ = cheerio.load(res.data); - const list = $('tr[height=50]').get(); - - const out = await Promise.all( - list.map((item) => { - const $ = cheerio.load(item); - const audit_status_td = $('td[style="font-weight:100 ;color: black ;position: relative;left:20px"]'); - const audit_status = audit_status_td.eq(-1).text(); - const title = '【' + audit_status + '】' + $('li.templateTip').text(); - const audit_date = audit_status_td.eq(-1).next('td').text(); - - let audit_desc = ''; - if (audit_status_td.length > 1) { - for (let i = 0; i < audit_status_td.length; i++) { - audit_desc += audit_status_td.eq(i).next('td').text() + ',' + audit_status_td.eq(i).text() + ';'; - } - } else { - audit_desc = audit_date + ',' + audit_status; - } - - const description = $('li.templateTip').text() + ':' + audit_desc; - const itemUrl = item_url; - - const single = { - title, - description, - pubDate: new Date(audit_date).toUTCString(), - link: itemUrl, - guid: itemUrl, - }; - return Promise.resolve(single); - }) - ); - ctx.state.data = { - title: '申请事项进度查询 - 中国证监会', - link: item_url, - item: out, - }; -}; diff --git a/lib/routes/csrc/fashenwei.js b/lib/routes/csrc/fashenwei.js deleted file mode 100644 index 128c18029..000000000 --- a/lib/routes/csrc/fashenwei.js +++ /dev/null @@ -1,42 +0,0 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); - -module.exports = async (ctx) => { - const url = 'http://www.csrc.gov.cn/pub/zjhpublic/3300/3621/index_7401.htm'; - const ori_url = 'http://www.csrc.gov.cn/pub/zjhpublic/'; - const res = await got.get(url); - const $ = cheerio.load(res.data); - const list = $('.row').get(); - - const out = await Promise.all( - list.map(async (item) => { - const $ = cheerio.load(item); - const time = $('li.fbrq').text(); - const title = $('li.mc > div').text(); - const sub_url = $('li.mc > div').find('a').attr('href').slice(6); - const itemUrl = ori_url + sub_url; - const cache = await ctx.cache.get(itemUrl); - if (cache) { - return Promise.resolve(JSON.parse(cache)); - } - - const responses = await got.get(itemUrl); - const $d = cheerio.load(responses.data); - - const single = { - title, - pubDate: new Date(time).toUTCString(), - link: itemUrl, - guid: itemUrl, - description: $d('#ContentRegion .Custom_UnionStyle').html(), - }; - ctx.cache.set(itemUrl, JSON.stringify(single)); - return Promise.resolve(single); - }) - ); - ctx.state.data = { - title: $('title').text(), - link: url, - item: out, - }; -}; diff --git a/lib/routes/csrc/news.js b/lib/routes/csrc/news.js deleted file mode 100644 index 0ee5e93ad..000000000 --- a/lib/routes/csrc/news.js +++ /dev/null @@ -1,45 +0,0 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); -const { resolve } = require('url'); - -module.exports = async (ctx) => { - let suffix = ctx.params.suffix || 'zjhxwfb-xwdd'; - suffix = suffix.replace('-', '/'); - const url = resolve('http://www.csrc.gov.cn/pub/newsite/', suffix + '/'); - const res = await got.get(url); - const $ = cheerio.load(res.data); - const title = $('div.title .bt').text(); - const list = $('.fl_list li').get(); - - const out = await Promise.all( - list.map(async (item) => { - const $ = cheerio.load(item); - const time = $('span').text(); - const title = $('a').text(); - const sub_url = $('a').attr('href'); - const itemUrl = resolve(url, sub_url); - const cache = await ctx.cache.get(itemUrl); - if (cache) { - return Promise.resolve(JSON.parse(cache)); - } - - const responses = await got.get(itemUrl); - const $d = cheerio.load(responses.data); - - const single = { - title, - pubDate: new Date(time).toUTCString(), - link: itemUrl, - guid: itemUrl, - description: $d('.content .Custom_UnionStyle').html() || $d('.contentss').html() || $d('.Section0').html(), - }; - ctx.cache.set(itemUrl, JSON.stringify(single)); - return Promise.resolve(single); - }) - ); - ctx.state.data = { - title: `中国证券监督管理委员会-${title}`, - link: url, - item: out, - }; -}; diff --git a/lib/v2/gov/csrc/auditstatus.js b/lib/v2/gov/csrc/auditstatus.js new file mode 100644 index 000000000..36e36ad38 --- /dev/null +++ b/lib/v2/gov/csrc/auditstatus.js @@ -0,0 +1,54 @@ +const cheerio = require('cheerio'); +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); +const md5 = require('@/utils/md5'); + +module.exports = async (ctx) => { + const baseUrl = 'https://neris.csrc.gov.cn'; + const { apply_id } = ctx.params; + const itemUrl = `${baseUrl}/alappl/home1/onlinealog`; + const res = await got(itemUrl, { + searchParams: { + appMatrCde: apply_id, + }, + }); + const $ = cheerio.load(res.data); + + const out = $('tr[height="50"]') + .toArray() + .map((item) => { + item = $(item); + const itemTitle = item.find('li.templateTip').text(); + const audit_status_td = item.find('td[style="font-weight:100 ;color: black ;position: relative;left:20px"]'); + const audit_status = audit_status_td.eq(-1).text(); + const title = '【' + audit_status + '】' + itemTitle; + const audit_date = audit_status_td.eq(-1).next('td').text(); + + let audit_desc = ''; + if (audit_status_td.length > 1) { + for (let i = 0; i < audit_status_td.length; i++) { + audit_desc += audit_status_td.eq(i).next('td').text() + ',' + audit_status_td.eq(i).text() + ';'; + } + } else { + audit_desc = audit_date + ',' + audit_status; + } + + const description = itemTitle + ':' + audit_desc; + + const single = { + title, + description, + pubDate: timezone(parseDate(audit_date), 8), + link: res.url, + guid: `${res.url}#${md5(description)}`, + }; + return single; + }); + + ctx.state.data = { + title: `${$('.zx2 div').attr('title')} - 申请事项进度查询 - 中国证监会`, + link: res.url, + item: out, + }; +}; diff --git a/lib/v2/gov/csrc/news.js b/lib/v2/gov/csrc/news.js new file mode 100644 index 000000000..41656c2d3 --- /dev/null +++ b/lib/v2/gov/csrc/news.js @@ -0,0 +1,69 @@ +const cheerio = require('cheerio'); +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); +const { art } = require('@/utils/render'); +const path = require('path'); + +module.exports = async (ctx) => { + const baseUrl = 'http://www.csrc.gov.cn'; + const { suffix = 'c100028/common_xq_list.shtml' } = ctx.params; + const link = `${baseUrl}/csrc/${suffix}`; + const { data: res } = await got(link); + const $ = cheerio.load(res); + + const channelId = $('meta[name="channelid"]').attr('content'); + + let data, + out = []; + if (channelId) { + data = await got(`${baseUrl}/searchList/${channelId}`, { + searchParams: { + _isAgg: true, + _isJson: true, + _pageSize: 18, + _template: 'index', + _rangeTimeGte: '', + _channelName: '', + page: 1, + }, + }); + + out = data.data.data.results.map((item) => ({ + title: item.title, + description: item.contentHtml + art(path.join(__dirname, 'templates', 'attachment.art'), { attachments: item.resList }), + pubDate: parseDate(item.publishedTime, 'x'), + link: item.url, + })); + } else { + const list = $('#list li') + .toArray() + .map((item) => { + item = $(item); + const a = item.find('a'); + return { + title: a.text(), + link: `${baseUrl}${a.attr('href')}`, + pubDate: timezone(parseDate(item.find('.data').text(), 'YYYY-MM-DD'), 8), + }; + }); + + out = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: res } = await got(item.link); + const $ = cheerio.load(res); + item.description = $('.detail-news').html(); + return item; + }) + ) + ); + } + + ctx.state.data = { + title: `中国证券监督管理委员会 - ${data?.data.channelName || $('head title').text()}`, + link, + image: 'http://www.csrc.gov.cn/favicon.ico', + item: out, + }; +}; diff --git a/lib/v2/gov/csrc/templates/attachment.art b/lib/v2/gov/csrc/templates/attachment.art new file mode 100644 index 000000000..772610f77 --- /dev/null +++ b/lib/v2/gov/csrc/templates/attachment.art @@ -0,0 +1,3 @@ +{{ each attachments a }} + {{ a.fileName }} +{{ /each }} diff --git a/lib/v2/gov/maintainer.js b/lib/v2/gov/maintainer.js index db91bcd2b..583454dac 100644 --- a/lib/v2/gov/maintainer.js +++ b/lib/v2/gov/maintainer.js @@ -12,6 +12,8 @@ module.exports = { '/cmse/kpjy/:id': ['nczitzk'], '/cmse/:path+': ['nczitzk'], '/cnnic/:path+': ['nczitzk'], + '/csrc/auditstatus/:apply_id': ['hillerliao'], + '/csrc/news/:suffix*': ['chinobing', 'LogicJake'], '/customs/list/:gchannel?': ['Jeason0228', 'TonyRL', 'he1q'], '/fmprc/:category?': ['nicolaszf', 'nczitzk'], '/immiau/news': ['liu233w'], diff --git a/lib/v2/gov/radar.js b/lib/v2/gov/radar.js index d6928a592..57293a74a 100644 --- a/lib/v2/gov/radar.js +++ b/lib/v2/gov/radar.js @@ -406,6 +406,25 @@ module.exports = { }, ], }, + 'csrc.gov.cn': { + _name: '中国证券监督管理委员会', + neris: [ + { + title: '申请事项进度', + docs: 'https://docs.rsshub.app/government.html#zhong-guo-zheng-quan-jian-du-guan-li-wei-yuan-hui', + source: ['/alappl/home1/onlinealog'], + target: (_, url) => `/gov/csrc/auditstatus/${new URL(url).searchParams.get('appMatrCde')}`, + }, + ], + www: [ + { + title: '通用', + docs: 'https://docs.rsshub.app/government.html#zhong-guo-zheng-quan-jian-du-guan-li-wei-yuan-hui', + source: ['/csrc/*suffix'], + target: '/gov/csrc/:suffix', + }, + ], + }, 'customs.gov.cn': { _name: '中华人民共和国海关总署', www: [ diff --git a/lib/v2/gov/router.js b/lib/v2/gov/router.js index d6e360fc1..47ea7263e 100644 --- a/lib/v2/gov/router.js +++ b/lib/v2/gov/router.js @@ -4,6 +4,8 @@ module.exports = function (router) { router.get('/cmse/fxrw', require('./cmse/fxrw')); router.get(/cmse(\/[\w/-]+)?/, require('./cmse')); router.get(/cnnic(\/[\w/-]+)?/, require('./cnnic')); + router.get('/csrc/auditstatus/:apply_id', require('./csrc/auditstatus')); + router.get('/csrc/news/:suffix*', require('./csrc/news')); router.get('/customs/list/:gchannel?', require('./customs/list')); router.get('/fmprc/:category?', require('./mfa/wjdt')); router.get('/immiau/news', require('./immiau/news'));