From 7a259bf4941a80ecfcf311e94de2d0735a040b58 Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Mon, 1 Jan 2024 00:36:21 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=9B=BD=E5=AE=B6?= =?UTF-8?q?=E6=B0=94=E5=80=99=E4=B8=AD=E5=BF=83=E6=9C=80=E6=96=B0=E7=9B=91?= =?UTF-8?q?=E6=B5=8B=20(#14151)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 国家气候中心最新监测 * fix typo --- lib/v2/ncc-cma/cmdp.js | 81 ++++++++ lib/v2/ncc-cma/maintainer.js | 3 + lib/v2/ncc-cma/radar.js | 229 +++++++++++++++++++++++ lib/v2/ncc-cma/router.js | 3 + lib/v2/ncc-cma/templates/description.art | 9 + website/docs/routes/forecast.mdx | 71 +++++++ 6 files changed, 396 insertions(+) create mode 100644 lib/v2/ncc-cma/cmdp.js create mode 100644 lib/v2/ncc-cma/maintainer.js create mode 100644 lib/v2/ncc-cma/radar.js create mode 100644 lib/v2/ncc-cma/router.js create mode 100644 lib/v2/ncc-cma/templates/description.art diff --git a/lib/v2/ncc-cma/cmdp.js b/lib/v2/ncc-cma/cmdp.js new file mode 100644 index 000000000..9a15d9317 --- /dev/null +++ b/lib/v2/ncc-cma/cmdp.js @@ -0,0 +1,81 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); +const iconv = require('iconv-lite'); + +module.exports = async (ctx) => { + const { id } = ctx.params; + const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 50; + + const ids = id?.split(/\//) ?? []; + const titles = []; + + const rootUrl = 'http://cmdp.ncc-cma.net'; + const currentUrl = new URL('cn/index.htm', rootUrl).href; + + const { data: response } = await got(currentUrl, { + responseType: 'buffer', + }); + + const $ = cheerio.load(iconv.decode(response, 'gbk')); + + const author = '国家气候中心'; + + const items = $('ul.img-con-new-con li img[id]') + .toArray() + .filter((item) => ids.length === 0 || ids.includes($(item).prop('id'))) + .slice(0, limit) + .map((item) => { + item = $(item); + + const id = item.prop('id'); + const title = $(`li[data-id="${id}"]`).text() || undefined; + const src = new URL(item.prop('src'), currentUrl).href; + const date = + src + .match(/_(\d{4})(\d{2})(\d{2})_/) + ?.slice(1, 4) + .join('-') ?? new Date().toISOString().slice(0, 10); + + if (ids.length !== 0 && title) { + titles.push(title); + } + + return { + title: `${title} ${date}`, + link: currentUrl, + description: art(path.join(__dirname, 'templates/description.art'), { + image: { + src, + alt: `${title} ${date}`, + }, + }), + author, + category: [title], + guid: `ncc-cma#${id}#${date}`, + pubDate: parseDate(date), + enclosure_url: src, + enclosure_type: `image/${src.split(/\./).pop()}`, + }; + }); + + const subtitle = $('h1').last().text(); + const image = $('img.logo').prop('src'); + const icon = new URL('favicon.ico', rootUrl).href; + + ctx.state.data = { + item: items, + title: `${author} - ${subtitle}${titles.length === 0 ? '' : ` - ${titles.join('|')}`}`, + link: currentUrl, + description: $('title').text(), + language: 'zh', + image, + icon, + logo: icon, + subtitle, + author, + allowEmpty: true, + }; +}; diff --git a/lib/v2/ncc-cma/maintainer.js b/lib/v2/ncc-cma/maintainer.js new file mode 100644 index 000000000..f3aa9916c --- /dev/null +++ b/lib/v2/ncc-cma/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/cmdp/image/:id?': ['nczitzk'], +}; diff --git a/lib/v2/ncc-cma/radar.js b/lib/v2/ncc-cma/radar.js new file mode 100644 index 000000000..583e0e9d4 --- /dev/null +++ b/lib/v2/ncc-cma/radar.js @@ -0,0 +1,229 @@ +module.exports = { + 'ncc-cma.net': { + _name: '国家气候中心', + cmdp: [ + { + title: '中国气温 - 日平均气温距平', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/RPJQWQYZ', + }, + { + title: '中国气温 - 近5天平均气温距平', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/ZJ5TPJQWJP', + }, + { + title: '中国气温 - 近10天平均气温距平', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/ZJ10TQWJP', + }, + { + title: '中国气温 - 近20天平均气温距平', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/ZJ20TQWJP', + }, + { + title: '中国气温 - 近30天平均气温距平', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/ZJ30TQWJP', + }, + { + title: '中国气温 - 本月以来气温距平', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/BYYLQWJP', + }, + { + title: '中国气温 - 本季以来气温距平', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/BJYLQWJP', + }, + { + title: '中国气温 - 本年以来气温距平', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/BNYLQWJP', + }, + { + title: '中国降水 - 日降水量分布', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/QGRJSLFBT0808S', + }, + { + title: '中国降水 - 近5天降水量', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/ZJ5TJSLFBT', + }, + { + title: '中国降水 - 近10天降水量', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/ZJ10TJSL', + }, + { + title: '中国降水 - 近20天降水量', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/ZJ20TJSL', + }, + { + title: '中国降水 - 近30天降水量', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/ZJ30TJSL', + }, + { + title: '中国降水 - 本月以来降水量', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/BYYLJSL', + }, + { + title: '中国降水 - 本季以来降水量', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/BJYLJSL', + }, + { + title: '中国降水 - 近10天降水量距平百分率', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/ZJ10TJSLJP', + }, + { + title: '中国降水 - 近20天降水量距平百分率', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/ZJ20TJSLJP', + }, + { + title: '中国降水 - 近30天降水量距平百分率', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/ZJ30TJSLJP', + }, + { + title: '中国降水 - 本月以来降水量距平百分率', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/BYYLJSLJPZYQHZ', + }, + { + title: '中国降水 - 本季以来降水量距平百分率', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/BJYLJSLJPZJQHZ', + }, + { + title: '中国降水 - 本年以来降水量距平百分率', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/BNYLJSLJP', + }, + { + title: '全球气温 - 气温距平(最近10天)', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/glbtmeana10_', + }, + { + title: '全球气温 - 气温距平(最近20天)', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/glbtmeana20_', + }, + { + title: '全球气温 - 气温距平(最近30天)', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/glbtmeana30_', + }, + { + title: '全球气温 - 气温距平(最近90天)', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/glbtmeana90_', + }, + { + title: '全球气温 - 最低气温距平(最近30天)', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/glbtmina30_', + }, + { + title: '全球气温 - 最低气温距平(最近90天)', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/glbtmina90_', + }, + { + title: '全球气温 - 最高气温距平(最近30天)', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/glbtmaxa30_', + }, + { + title: '全球气温 - 最高气温距平(最近90天)', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/glbtmaxa90_', + }, + { + title: '全球降水 - 降水量(最近10天)', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/glbrain10_', + }, + { + title: '全球降水 - 降水量(最近20天)', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/glbrain20_', + }, + { + title: '全球降水 - 降水量(最近30天)', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/glbrain30_', + }, + { + title: '全球降水 - 降水量(最近90天)', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/glbrain90_', + }, + { + title: '全球降水 - 降水距平百分率(最近10天)', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/glbraina10_', + }, + { + title: '全球降水 - 降水距平百分率(最近20天)', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/glbraina20_', + }, + { + title: '全球降水 - 降水距平百分率(最近30天)', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/glbraina30_', + }, + { + title: '全球降水 - 降水距平百分率(最近90天)', + docs: 'https://docs.rsshub.app/routes/forecast#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce', + source: ['/cn/index.htm'], + target: '/ncc-cma/cmdp/image/glbraina90_', + }, + ], + }, +}; diff --git a/lib/v2/ncc-cma/router.js b/lib/v2/ncc-cma/router.js new file mode 100644 index 000000000..d2be06c8b --- /dev/null +++ b/lib/v2/ncc-cma/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/cmdp/image/:id*', require('./cmdp')); +}; diff --git a/lib/v2/ncc-cma/templates/description.art b/lib/v2/ncc-cma/templates/description.art new file mode 100644 index 000000000..baa091693 --- /dev/null +++ b/lib/v2/ncc-cma/templates/description.art @@ -0,0 +1,9 @@ +{{ if image?.src }} +
+ {{ image.alt }} +
+{{ /if }} \ No newline at end of file diff --git a/website/docs/routes/forecast.mdx b/website/docs/routes/forecast.mdx index bb8faf736..2f17b104e 100644 --- a/website/docs/routes/forecast.mdx +++ b/website/docs/routes/forecast.mdx @@ -68,6 +68,77 @@ +## 国家气候中心 {#guo-jia-qi-hou-zhong-xin} + +### 最新监测 {#guo-jia-qi-hou-zhong-xin-zui-xin-jian-ce} + + + :::tip + 若订阅全部最新监测信息,此时路由为 [`/ncc-cma/cmdp/image`](https://rsshub.app/ncc-cma/cmdp/image)。 + + 若订阅中国气温 **日平均气温距平** 的最新监测信息,此时路由为 [`/ncc-cma/cmdp/image/RPJQWQYZ`](https://rsshub.app/ncc-cma/cmdp/image/RPJQWQYZ)。 + + 若订阅全球降水 **降水量(最近 10 天)** / **降水量(最近 10 天)** / **降水量(最近 10 天)** 的最新监测信息,此时路由为 [`/ncc-cma/cmdp/image/glbrain10_/glbrain20_/glbrain30_`](https://rsshub.app/ncc-cma/cmdp/image/glbrain10_/glbrain20_/glbrain30_)。 + ::: + + #### [中国气温](http://cmdp.ncc-cma.net/cn/index.htm) + + | 分类 | ID | + | -------------------- | ---------- | + | 日平均气温距平 | RPJQWQYZ | + | 近 5 天平均气温距平 | ZJ5TPJQWJP | + | 近 10 天平均气温距平 | ZJ10TQWJP | + | 近 20 天平均气温距平 | ZJ20TQWJP | + | 近 30 天平均气温距平 | ZJ30TQWJP | + | 本月以来气温距平 | BYYLQWJP | + | 本季以来气温距平 | BJYLQWJP | + | 本年以来气温距平 | BNYLQWJP | + + #### [中国降水](http://cmdp.ncc-cma.net/cn/index.htm) + + | 分类 | ID | + | ------------------------ | -------------- | + | 日降水量分布 | QGRJSLFBT0808S | + | 近 5 天降水量 | ZJ5TJSLFBT | + | 近 10 天降水量 | ZJ10TJSL | + | 近 20 天降水量 | ZJ20TJSL | + | 近 30 天降水量 | ZJ30TJSL | + | 本月以来降水量 | BYYLJSL | + | 本季以来降水量 | BJYLJSL | + | 近 10 天降水量距平百分率 | ZJ10TJSLJP | + | 近 20 天降水量距平百分率 | ZJ20TJSLJP | + | 近 30 天降水量距平百分率 | ZJ30TJSLJP | + | 本月以来降水量距平百分率 | BYYLJSLJPZYQHZ | + | 本季以来降水量距平百分率 | BJYLJSLJPZJQHZ | + | 本年以来降水量距平百分率 | BNYLJSLJP | + + #### [全球气温](http://cmdp.ncc-cma.net/cn/index.htm) + + | 分类 | ID | + | -------------------------- | ------------- | + | 气温距平(最近 10 天) | glbtmeana10\_ | + | 气温距平(最近 20 天) | glbtmeana20\_ | + | 气温距平(最近 30 天) | glbtmeana30\_ | + | 气温距平(最近 90 天) | glbtmeana90\_ | + | 最低气温距平(最近 30 天) | glbtmina30\_ | + | 最低气温距平(最近 90 天) | glbtmina90\_ | + | 最高气温距平(最近 30 天) | glbtmaxa30\_ | + | 最高气温距平(最近 90 天) | glbtmaxa90\_ | + + #### [全球降水](http://cmdp.ncc-cma.net/cn/index.htm) + + | 分类 | ID | + | ---------------------------- | ------------ | + | 降水量(最近 10 天) | glbrain10\_ | + | 降水量(最近 20 天) | glbrain20\_ | + | 降水量(最近 30 天) | glbrain30\_ | + | 降水量(最近 90 天) | glbrain90\_ | + | 降水距平百分率(最近 10 天) | glbraina10\_ | + | 降水距平百分率(最近 20 天) | glbraina20\_ | + | 降水距平百分率(最近 30 天) | glbraina30\_ | + | 降水距平百分率(最近 90 天) | glbraina90\_ | + + ## 国家突发事件预警信息发布网 {#guo-jia-tu-fa-shi-jian-yu-jing-xin-xi-fa-bu-wang} ### 当前生效预警 {#guo-jia-tu-fa-shi-jian-yu-jing-xin-xi-fa-bu-wang-dang-qian-sheng-xiao-yu-jing}