diff --git a/lib/router.js b/lib/router.js index b1a0e8069796f1..80d0cfa6fc3c01 100644 --- a/lib/router.js +++ b/lib/router.js @@ -155,7 +155,7 @@ router.get('/mafengwo/ziyouxing/:code', lazyloadRouteHandler('./routes/mafengwo/ router.get('/novel/uukanshu/:uid', lazyloadRouteHandler('./routes/novel/uukanshu')); // 中国气象网 -router.get('/weatheralarm/:province?', lazyloadRouteHandler('./routes/weatheralarm')); +// router.get('/weatheralarm/:province?', lazyloadRouteHandler('./routes/weatheralarm')); // Gitlab router.get('/gitlab/explore/:type/:host?', lazyloadRouteHandler('./routes/gitlab/explore')); diff --git a/lib/routes-deprecated/weatheralarm/index.js b/lib/routes-deprecated/weatheralarm/index.js deleted file mode 100644 index 88d0595378443d..00000000000000 --- a/lib/routes-deprecated/weatheralarm/index.js +++ /dev/null @@ -1,26 +0,0 @@ -const got = require('@/utils/got'); - -module.exports = async (ctx) => { - const province = ctx.params.province || '&'; - const alarmInfoURL = `http://www.nmc.cn/rest/findAlarm?pageNo=1&pageSize=20&signaltype=&signallevel=&province=${province}`; - const response = await got({ - method: 'get', - url: alarmInfoURL, - }); - const data = response.data.data; - const list = data.page.list; - - ctx.state.data = { - title: '中央气象台全国气象预警', - link: `http://www.nmc.cn/publish/alarm.html`, - item: list.map((item) => { - const title = item.title; - const url = item.url; - return { - title, - link: `http://www.nmc.cn${url}`, - pubDate: item.issuetime, - }; - }), - }; -}; diff --git a/lib/routes/nmc/maintainer.js b/lib/routes/nmc/maintainer.js new file mode 100644 index 00000000000000..42f2f53ab7a2ce --- /dev/null +++ b/lib/routes/nmc/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/weatheralarm/:province?': ['ylc395'], +}; diff --git a/lib/routes/nmc/radar.js b/lib/routes/nmc/radar.js new file mode 100644 index 00000000000000..0e77a18f3ecc65 --- /dev/null +++ b/lib/routes/nmc/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'nmc.cn': { + _name: '中央气象台', + '.': [ + { + title: '全国气象预警', + docs: 'https://docs.rsshub.app/routes/forecast#zhong-yang-qi-xiang-tai', + source: ['/publish/alarm.html', '/'], + target: '/nmc/weatheralarm', + }, + ], + }, +}; diff --git a/lib/routes/nmc/router.js b/lib/routes/nmc/router.js new file mode 100644 index 00000000000000..fde453364bb8ec --- /dev/null +++ b/lib/routes/nmc/router.js @@ -0,0 +1,3 @@ +export default (router) => { + router.get('/weatheralarm/:province?', './weatheralarm'); +}; diff --git a/lib/routes/nmc/weatheralarm.js b/lib/routes/nmc/weatheralarm.js new file mode 100644 index 00000000000000..825d35650ff389 --- /dev/null +++ b/lib/routes/nmc/weatheralarm.js @@ -0,0 +1,49 @@ +import cache from '@/utils/cache'; +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; +import * as cheerio from 'cheerio'; + +export default async (ctx) => { + const { province } = ctx.req.param(); + const alarmInfoURL = `http://www.nmc.cn/rest/findAlarm`; + const { data: response } = await got(alarmInfoURL, { + searchParams: { + pageNo: 1, + pageSize: 20, + signaltype: '', + signallevel: '', + province, + }, + }); + + const list = response.data.page.list.map((item) => ({ + title: item.title, + link: `http://www.nmc.cn${item.url}`, + pubDate: timezone(parseDate(item.issuetime), 8), + })); + + const items = await Promise.all( + list.map((item) => + cache.tryGet(item.link, async () => { + const { data: response } = await got(item.link); + const $ = cheerio.load(response); + + item.description = + $('#icon').html() + + $('#alarmtext') + .toArray() + .map((i) => $(i).html()) + .join(''); + + return item; + }) + ) + ); + + ctx.set('data', { + title: '中央气象台全国气象预警', + link: 'http://www.nmc.cn/publish/alarm.html', + item: items, + }); +}; diff --git a/website/docs/routes/forecast.mdx b/website/docs/routes/forecast.mdx index 2f17b104edabbe..b3bd703fd854e7 100644 --- a/website/docs/routes/forecast.mdx +++ b/website/docs/routes/forecast.mdx @@ -316,6 +316,6 @@ ### 全国气象预警 {#zhong-yang-qi-xiang-tai-quan-guo-qi-xiang-yu-jing} - + 可通过全局过滤参数订阅您感兴趣的地区.