feat(route): add 国家气候中心最新监测 (#14151)

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

* fix typo
This commit is contained in:
Ethan Shen
2024-01-01 00:36:21 +08:00
committed by GitHub
parent f20bca610f
commit 7a259bf494
6 changed files with 396 additions and 0 deletions
+81
View File
@@ -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,
};
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/cmdp/image/:id?': ['nczitzk'],
};
+229
View File
@@ -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_',
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/cmdp/image/:id*', require('./cmdp'));
};
+9
View File
@@ -0,0 +1,9 @@
{{ if image?.src }}
<figure>
<img
{{ if image.alt }}
alt="{{ image.alt }}"
{{ /if }}
src="{{ image.src }}">
</figure>
{{ /if }}