From 31f84a97068bf522ee1cefb57eec127b8d1a6bb1 Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Tue, 5 Jul 2022 21:34:03 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E4=B8=8A=E6=B5=B7?= =?UTF-8?q?=E5=B8=82=E8=8D=AF=E5=93=81=E7=9B=91=E7=9D=A3=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=B1=80=20(#10138)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 上海市药品监督管理局 * fix typo --- docs/government.md | 14 +++++++++ lib/v2/gov/maintainer.js | 1 + lib/v2/gov/radar.js | 10 +++++- lib/v2/gov/router.js | 1 + lib/v2/gov/shanghai/yjj/index.js | 54 ++++++++++++++++++++++++++++++++ 5 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 lib/v2/gov/shanghai/yjj/index.js diff --git a/docs/government.md b/docs/government.md index 9f777df63..10d241860 100644 --- a/docs/government.md +++ b/docs/government.md @@ -388,6 +388,20 @@ pageClass: routes +### 上海市药品监督管理局 + + + +::: tip 提示 + +路径处填写对应页面 URL 中 `https://yjj.sh.gov.cn/` 与 `/index.html` 之间的字段,下面是一个例子。 + +若订阅 [最新信息公开 > 综合](https://yjj.sh.gov.cn/zh/index.html) 则将对应页面 URL 中 `https://yjj.sh.gov.cn/` 和 `/index.html` 之间的字段 `zh` 作为路径填入。此时路由为 [`/gov/shanghai/yjj/zh`](https://rsshub.app/gov/shanghai/yjj/zh) + +::: + + + ## 世界贸易组织 ### 争端解决新闻 diff --git a/lib/v2/gov/maintainer.js b/lib/v2/gov/maintainer.js index 6e7fcb558..a8deb6f6d 100644 --- a/lib/v2/gov/maintainer.js +++ b/lib/v2/gov/maintainer.js @@ -26,6 +26,7 @@ module.exports = { '/shenzhen/hrss/szksy/:caty/:page?': ['zlasd'], '/shenzhen/zzb/:caty/:page?': ['zlasd'], '/shanghai/rsj/ksxm': ['Fatpandac'], + '/shanghai/yjj/:path+': ['nczitzk'], '/shanghai/wsjkw/yqtb': ['zcf0508'], '/guangdong/tqyb/tfxtq': ['Fatpandac'], '/guangdong/tqyb/sncsyjxh': ['Fatpandac'], diff --git a/lib/v2/gov/radar.js b/lib/v2/gov/radar.js index db9f6f07f..62d35169e 100644 --- a/lib/v2/gov/radar.js +++ b/lib/v2/gov/radar.js @@ -514,11 +514,19 @@ module.exports = { rsj: [ { title: '上海市职业能力考试院 考试项目', - docs: 'https://docs.rsshub.app/government.html#shang-hai-shi-zhi-ye-neng-li-kao-shi-yuan-kao-shi-xiang-mu', + docs: 'https://docs.rsshub.app/government.html#shang-hai-shi-ren-min-zheng-fu-shang-hai-shi-zhi-ye-neng-li-kao-shi-yuan-kao-shi-xiang-mu', source: ['/'], target: '/gov/shanghai/rsj/ksxm', }, ], + yjj: [ + { + title: '上海市药品监督管理局', + docs: 'https://docs.rsshub.app/government.html#shang-hai-shi-ren-min-zheng-fu-shang-hai-shi-yao-pin-jian-du-guan-li-ju', + source: ['/'], + target: (params, url) => `/gov/shanghai/yjj/${new URL(url).match(/yjj\.sh\.gov\.cn\/(.*)\/index.html/)[1]}`, + }, + ], }, 'shaanxi.gov.cn': { _name: '陕西省人民政府', diff --git a/lib/v2/gov/router.js b/lib/v2/gov/router.js index 609bd615a..3163b64a4 100644 --- a/lib/v2/gov/router.js +++ b/lib/v2/gov/router.js @@ -26,6 +26,7 @@ module.exports = function (router) { router.get('/shenzhen/hrss/szksy/:caty/:page?', require('./shenzhen/hrss/szksy/index')); router.get('/shenzhen/zzb/:caty/:page?', require('./shenzhen/zzb/index')); router.get('/shanghai/rsj/ksxm', require('./shanghai/rsj/ksxm')); + router.get(/shanghai\/yjj\/([\w/-]+)?/, require('./shanghai/yjj')); router.get('/shanghai/wsjkw/yqtb', require('./shanghai/wsjkw/yqtb')); router.get('/guangdong/tqyb/tfxtq', require('./guangdong/tqyb/tfxtq')); router.get('/guangdong/tqyb/sncsyjxh', require('./guangdong/tqyb/sncsyjxh')); diff --git a/lib/v2/gov/shanghai/yjj/index.js b/lib/v2/gov/shanghai/yjj/index.js new file mode 100644 index 000000000..a105116aa --- /dev/null +++ b/lib/v2/gov/shanghai/yjj/index.js @@ -0,0 +1,54 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const params = ctx.path === '/shanghai/yjj' ? '/shanghai/yjj/zx-ylqx' : ctx.path; + + const rootUrl = 'https://yjj.sh.gov.cn'; + const currentUrl = `${rootUrl}${params.replace(/^\/shanghai\/yjj/, '')}/index.html`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + let items = $('.pageList li a') + .toArray() + .map((item) => { + item = $(item); + + return { + title: item.text(), + link: `${rootUrl}${item.attr('href')}`, + pubDate: parseDate(item.next().text()), + }; + }); + + items = await Promise.all( + items.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('#ivs_content').html(); + item.pubDate = timezone(parseDate(content('meta[name="pubdate"]').attr('content')), +8); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text().replace(/--/, ' - '), + link: currentUrl, + item: items, + }; +};