fix(route): 国家气候中心最新监测 (#15490)

* fix(route): 国家气候中心最新监测

* update cmdp.ts

* update namespace.ts
This commit is contained in:
Ethan Shen 2024-05-08 01:12:00 +08:00 committed by GitHub
parent 9b09c12d9b
commit bf11a10f6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 293 additions and 34 deletions

View File

@ -9,16 +9,9 @@ import { art } from '@/utils/render';
import path from 'node:path';
import iconv from 'iconv-lite';
export const route: Route = {
path: '/cmdp/image/:id{.+}?',
name: 'Unknown',
maintainers: [],
handler,
};
async function handler(ctx) {
const id = ctx.req.param('id');
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 50;
export const handler = async (ctx) => {
const { id = 'RPJQWQYZ' } = ctx.req.param();
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 30;
const ids = id?.split(/\//) ?? [];
const titles = [];
@ -33,6 +26,7 @@ async function handler(ctx) {
const $ = load(iconv.decode(response, 'gbk'));
const author = '国家气候中心';
const language = 'zh';
const items = $('ul.img-con-new-con li img[id]')
.toArray()
@ -43,9 +37,9 @@ async function handler(ctx) {
const id = item.prop('id');
const title = $(`li[data-id="${id}"]`).text() || undefined;
const src = new URL(item.prop('src'), currentUrl).href;
const image = new URL(item.prop('src'), currentUrl).href;
const date =
src
image
.match(/_(\d{4})(\d{2})(\d{2})_/)
?.slice(1, 4)
.join('-') ?? new Date().toISOString().slice(0, 10);
@ -54,39 +48,302 @@ async function handler(ctx) {
titles.push(title);
}
const description = art(path.join(__dirname, 'templates/description.art'), {
images: image
? [
{
src: image,
alt: `${title} ${date}`,
},
]
: undefined,
});
const guid = `ncc-cma#${id}#${date}`;
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}`,
description,
pubDate: parseDate(date),
enclosure_url: src,
enclosure_type: `image/${src.split(/\./).pop()}`,
link: currentUrl,
category: [title],
author,
guid,
id: guid,
content: {
html: description,
text: description,
},
image,
banner: image,
language,
enclosure_url: image,
enclosure_type: `image/${image.split(/\./).pop()}`,
enclosure_title: `${title} ${date}`,
};
});
const subtitle = $('h1').last().text();
const image = $('img.logo').prop('src');
const icon = new URL('favicon.ico', rootUrl).href;
return {
item: items,
title: `${author} - ${subtitle}${titles.length === 0 ? '' : ` - ${titles.join('|')}`}`,
link: currentUrl,
description: $('title').text(),
language: 'zh',
image,
icon,
logo: icon,
subtitle,
author,
link: currentUrl,
item: items,
allowEmpty: true,
image,
author,
language,
};
}
};
export const route: Route = {
path: '/cmdp/image/:id{.+}?',
name: '最新监测',
url: 'cmdp.ncc-cma.net',
maintainers: ['nczitzk'],
handler,
example: '/ncc-cma/cmdp/image/RPJQWQYZ',
parameters: { category: '图片,默认为 RPJQWQYZ即日平均气温距平可在对应列表项 data-id 属性中找到' },
description: `:::tip
data-id \`RPJQWQYZ\` 作为参数填入,此时路由为 [\`/ncc-cma/cmdp/image/RPJQWQYZ\`](https://rsshub.app/ncc-cma/cmdp/image/RPJQWQYZ)。
510 data-id \`RPJQWQYZ\`\`ZJ5TPJQWJP\`\`ZJ10TQWJP\` 作为参数填入,此时路由为 [\`/ncc-cma/cmdp/image/RPJQWQYZ/ZJ5TPJQWJP/ZJ10TQWJP\`](https://rsshub.app/ncc-cma/cmdp/image/RPJQWQYZ/ZJ5TPJQWJP/ZJ10TQWJP)。
:::
| | 5 | 10 | 20 | 30 |
| ----------------------------------------------------------- | --------------------------------------------------------------- | ------------------------------------------------------------- | ------------------------------------------------------------- | ------------------------------------------------------------- |
| [RPJQWQYZ](https://rsshub.app/ncc-cma/cmdp/image/RPJQWQYZ) | [ZJ5TPJQWJP](https://rsshub.app/ncc-cma/cmdp/image/ZJ5TPJQWJP) | [ZJ10TQWJP](https://rsshub.app/ncc-cma/cmdp/image/ZJ10TQWJP) | [ZJ20TQWJP](https://rsshub.app/ncc-cma/cmdp/image/ZJ20TQWJP) | [ZJ30TQWJP](https://rsshub.app/ncc-cma/cmdp/image/ZJ30TQWJP) |
| | | |
| ----------------------------------------------------------- | ----------------------------------------------------------- | ----------------------------------------------------------- |
| [BYYLQWJP](https://rsshub.app/ncc-cma/cmdp/image/BYYLQWJP) | [BJYLQWJP](https://rsshub.app/ncc-cma/cmdp/image/BJYLQWJP) | [BNYLQWJP](https://rsshub.app/ncc-cma/cmdp/image/BNYLQWJP) |
| | 5 | 10 | 20 | 30 |
| ----------------------------------------------------------------------- | --------------------------------------------------------------- | ----------------------------------------------------------- | ----------------------------------------------------------- | ----------------------------------------------------------- |
| [QGRJSLFBT0808S](https://rsshub.app/ncc-cma/cmdp/image/QGRJSLFBT0808S) | [ZJ5TJSLFBT](https://rsshub.app/ncc-cma/cmdp/image/ZJ5TJSLFBT) | [ZJ10TJSL](https://rsshub.app/ncc-cma/cmdp/image/ZJ10TJSL) | [ZJ20TJSL](https://rsshub.app/ncc-cma/cmdp/image/ZJ20TJSL) | [ZJ30TJSL](https://rsshub.app/ncc-cma/cmdp/image/ZJ30TJSL) |
| | | 10 | 20 | 30 |
| --------------------------------------------------------- | --------------------------------------------------------- | --------------------------------------------------------------- | --------------------------------------------------------------- | --------------------------------------------------------------- |
| [BYYLJSL](https://rsshub.app/ncc-cma/cmdp/image/BYYLJSL) | [BJYLJSL](https://rsshub.app/ncc-cma/cmdp/image/BJYLJSL) | [ZJ10TJSLJP](https://rsshub.app/ncc-cma/cmdp/image/ZJ10TJSLJP) | [ZJ20TJSLJP](https://rsshub.app/ncc-cma/cmdp/image/ZJ20TJSLJP) | [ZJ30TJSLJP](https://rsshub.app/ncc-cma/cmdp/image/ZJ30TJSLJP) |
| | | |
| ----------------------------------------------------------------------- | ----------------------------------------------------------------------- | ------------------------------------------------------------- |
| [BYYLJSLJPZYQHZ](https://rsshub.app/ncc-cma/cmdp/image/BYYLJSLJPZYQHZ) | [BJYLJSLJPZJQHZ](https://rsshub.app/ncc-cma/cmdp/image/BJYLJSLJPZJQHZ) | [BNYLJSLJP](https://rsshub.app/ncc-cma/cmdp/image/BNYLJSLJP) |
| 10 | 20 | 30 | 90 | 30 |
| -------------------------------------------------------------------- | -------------------------------------------------------------------- | -------------------------------------------------------------------- | -------------------------------------------------------------------- | ------------------------------------------------------------------ |
| [glbtmeana10\_](https://rsshub.app/ncc-cma/cmdp/image/glbtmeana10_) | [glbtmeana20\_](https://rsshub.app/ncc-cma/cmdp/image/glbtmeana20_) | [glbtmeana30\_](https://rsshub.app/ncc-cma/cmdp/image/glbtmeana30_) | [glbtmeana90\_](https://rsshub.app/ncc-cma/cmdp/image/glbtmeana90_) | [glbtmina30\_](https://rsshub.app/ncc-cma/cmdp/image/glbtmina30_) |
| 90 | 30 | 90 |
| ------------------------------------------------------------------ | ------------------------------------------------------------------ | ------------------------------------------------------------------ |
| [glbtmina90\_](https://rsshub.app/ncc-cma/cmdp/image/glbtmina90_) | [glbtmaxa30\_](https://rsshub.app/ncc-cma/cmdp/image/glbtmaxa30_) | [glbtmaxa90\_](https://rsshub.app/ncc-cma/cmdp/image/glbtmaxa90_) |
| 10 | 20 | 30 | 90 | 10 |
| ---------------------------------------------------------------- | ---------------------------------------------------------------- | ---------------------------------------------------------------- | ---------------------------------------------------------------- | ------------------------------------------------------------------ |
| [glbrain10\_](https://rsshub.app/ncc-cma/cmdp/image/glbrain10_) | [glbrain20\_](https://rsshub.app/ncc-cma/cmdp/image/glbrain20_) | [glbrain30\_](https://rsshub.app/ncc-cma/cmdp/image/glbrain30_) | [glbrain90\_](https://rsshub.app/ncc-cma/cmdp/image/glbrain90_) | [glbraina10\_](https://rsshub.app/ncc-cma/cmdp/image/glbraina10_) |
| 20 | 30 | 90 |
| ------------------------------------------------------------------ | ------------------------------------------------------------------ | ------------------------------------------------------------------ |
| [glbraina20\_](https://rsshub.app/ncc-cma/cmdp/image/glbraina20_) | [glbraina30\_](https://rsshub.app/ncc-cma/cmdp/image/glbraina30_) | [glbraina90\_](https://rsshub.app/ncc-cma/cmdp/image/glbraina90_) |
`,
categories: ['forecast'],
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportRadar: true,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
title: '日平均气温距平',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/RPJQWQYZ',
},
{
title: '近5天平均气温距平',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/ZJ5TPJQWJP',
},
{
title: '近10天平均气温距平',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/ZJ10TQWJP',
},
{
title: '近20天平均气温距平',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/ZJ20TQWJP',
},
{
title: '近30天平均气温距平',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/ZJ30TQWJP',
},
{
title: '本月以来气温距平',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/BYYLQWJP',
},
{
title: '本季以来气温距平',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/BJYLQWJP',
},
{
title: '本年以来气温距平',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/BNYLQWJP',
},
{
title: '日降水量分布',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/QGRJSLFBT0808S',
},
{
title: '近5天降水量',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/ZJ5TJSLFBT',
},
{
title: '近10天降水量',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/ZJ10TJSL',
},
{
title: '近20天降水量',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/ZJ20TJSL',
},
{
title: '近30天降水量',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/ZJ30TJSL',
},
{
title: '本月以来降水量',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/ncc-cma/cmdp/image/BYYLJSL',
},
{
title: '本季以来降水量',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/BJYLJSL',
},
{
title: '近10天降水量距平百分率',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/ZJ10TJSLJP',
},
{
title: '近20天降水量距平百分率',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/ZJ20TJSLJP',
},
{
title: '近30天降水量距平百分率',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/ZJ30TJSLJP',
},
{
title: '本月以来降水量距平百分率',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/BYYLJSLJPZYQHZ',
},
{
title: '本季以来降水量距平百分率',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/BJYLJSLJPZJQHZ',
},
{
title: '本年以来降水量距平百分率',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/BNYLJSLJP',
},
{
title: '气温距平最近10天',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/glbtmeana10_',
},
{
title: '气温距平最近20天',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/glbtmeana20_',
},
{
title: '气温距平最近30天',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/glbtmeana30_',
},
{
title: '气温距平最近90天',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/glbtmeana90_',
},
{
title: '最低气温距平最近30天',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/glbtmina30_',
},
{
title: '最低气温距平最近90天',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/glbtmina90_',
},
{
title: '最高气温距平最近30天',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/glbtmaxa30_',
},
{
title: '最高气温距平最近90天',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/glbtmaxa90_',
},
{
title: '降水量最近10天',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/glbrain10_',
},
{
title: '降水量最近20天',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/glbrain20_',
},
{
title: '降水量最近30天',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/glbrain30_',
},
{
title: '降水量最近90天',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/glbrain90_',
},
{
title: '降水距平百分率最近10天',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/glbraina10_',
},
{
title: '降水距平百分率最近20天',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/glbraina20_',
},
{
title: '降水距平百分率最近30天',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/glbraina30_',
},
{
title: '降水距平百分率最近90天',
source: ['cmdp.ncc-cma.net/cn/index.htm'],
target: '/cmdp/image/glbraina90_',
},
],
};

View File

@ -3,4 +3,6 @@ import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: '国家气候中心',
url: 'cmdp.ncc-cma.net',
categories: ['forecast'],
description: '',
};