From 98a4c7ad77fb8172733aff919682a56377d9ee86 Mon Sep 17 00:00:00 2001 From: Tony Date: Sat, 10 Dec 2022 08:36:41 -0700 Subject: [PATCH] feat(route): sasac (#11433) --- docs/government.md | 16 ++++++++++++++ lib/v2/gov/maintainer.js | 1 + lib/v2/gov/radar.js | 11 ++++++++++ lib/v2/gov/router.js | 1 + lib/v2/gov/sasac/generic.js | 42 +++++++++++++++++++++++++++++++++++++ 5 files changed, 71 insertions(+) create mode 100644 lib/v2/gov/sasac/generic.js diff --git a/docs/government.md b/docs/government.md index 931cc1d4c8..e268785898 100644 --- a/docs/government.md +++ b/docs/government.md @@ -369,6 +369,22 @@ pageClass: routes +## 国务院国有资产监督管理委员会 + +### 通用 + + + +::: tip 提示 + +路径处填写对应页面 URL 中 `http://www.sasac.gov.cn/` 与 `/index.html` 之间的字段,下面是一个例子。 + +若订阅 [其他](http://www.sasac.gov.cn/n2588030/n16436141/index.html) 则将对应页面 URL 中 `http://www.sasac.gov.cn/` 和 `/index.html` 之间的字段 `n2588030/n16436141` 作为路径填入。此时路由为 [`/gov/sasac/n2588030/n16436141`](https://rsshub.app/gov/nmpa/n2588030/n16436141) + +::: + + + ## 哈尔滨市科技局 ### 政务公开 diff --git a/lib/v2/gov/maintainer.js b/lib/v2/gov/maintainer.js index 17365a08fa..7ead7f607f 100644 --- a/lib/v2/gov/maintainer.js +++ b/lib/v2/gov/maintainer.js @@ -34,6 +34,7 @@ module.exports = { '/pbc/gzlw': ['Fatpandac'], '/pbc/tradeAnnouncement': ['nczitzk'], '/pbc/zcyj': ['Fatpandac'], + '/sasac/:path+': ['TonyRL'], '/stats/:path+': ['bigfei'], '/zhengce/govall/:advance?': ['ciaranchen'], '/zhengce/wenjian/:pcodeJiguan?': ['ciaranchen'], diff --git a/lib/v2/gov/radar.js b/lib/v2/gov/radar.js index b34a226c12..d444c786fd 100644 --- a/lib/v2/gov/radar.js +++ b/lib/v2/gov/radar.js @@ -694,6 +694,17 @@ module.exports = { }, ], }, + 'sasac.gov.cn': { + _name: '国务院国有资产监督管理委员会', + '.': [ + { + title: '通用', + docs: 'https://docs.rsshub.app/other.html#guo-wu-yuan-guo-you-zi-chan-jian-du-guan-li-wei-yuan-hui', + source: ['/*path'], + target: (params) => `/gov/sasac/${params.path.replace('/index.html', '')}`, + }, + ], + }, 'sh.gov.cn': { _name: '上海市人民政府', wsjkw: [ diff --git a/lib/v2/gov/router.js b/lib/v2/gov/router.js index 71a7be5906..dfcc6024a7 100644 --- a/lib/v2/gov/router.js +++ b/lib/v2/gov/router.js @@ -26,6 +26,7 @@ module.exports = function (router) { router.get('/pbc/gzlw', require('./pbc/gzlw')); router.get('/pbc/tradeAnnouncement', require('./pbc/tradeAnnouncement')); router.get('/pbc/zcyj', require('./pbc/zcyj')); + router.get('/sasac/:path+', require('./sasac/generic')); router.get(/stats(\/[\w/-]+)?/, require('./stats')); router.get('/zhengce/govall/:advance?', require('./zhengce/govall')); router.get('/zhengce/wenjian/:pcodeJiguan?', require('./zhengce/wenjian')); diff --git a/lib/v2/gov/sasac/generic.js b/lib/v2/gov/sasac/generic.js new file mode 100644 index 0000000000..dbc3ab83fe --- /dev/null +++ b/lib/v2/gov/sasac/generic.js @@ -0,0 +1,42 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const { path } = ctx.params; + const baseUrl = 'http://www.sasac.gov.cn'; + const url = `${baseUrl}/${path}/index.html`; + const response = await got(url); + + const $ = cheerio.load(response.data); + const list = $('.zsy_conlist li') + .toArray() + .filter((item) => !$(item).attr('style')) + .map((item) => { + item = $(item); + return { + title: item.find('a').attr('title'), + link: new URL(item.find('a').attr('href'), response.url).href, + pubDate: parseDate(item.find('span').text().replace('[', '').replace(']', '')), + }; + }); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const response = await got(item.link); + const $ = cheerio.load(response.data); + $('style, #qr_container, #div_div, [class^=jiathis]').remove(); + item.description = $('.zsy_comain').html(); + return item; + }) + ) + ); + + ctx.state.data = { + title: $('head title').text().trim(), + link: url, + image: 'http://www.sasac.gov.cn/dbsource/11869722/11869731.jpg', + item: items, + }; +};