mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-09 14:40:23 +08:00
feat: 修复路由 预报预警|全国气象预警 (#4511)
This commit is contained in:
@@ -98,7 +98,7 @@ pageClass: routes
|
||||
|
||||
### 全国气象预警
|
||||
|
||||
<Route author="ylc395" example="/weatheralarm" path="/weatheralarm">
|
||||
<Route author="ylc395" example="/weatheralarm/广东省" path="/weatheralarm/:province?" :paramsDesc="['省份']">
|
||||
|
||||
可通过全局过滤参数订阅您感兴趣的地区.
|
||||
|
||||
|
||||
@@ -528,7 +528,7 @@ router.get('/novel/ptwxz/:id1/:id2', require('./routes/novel/ptwxz'));
|
||||
router.get('/novel/zhaishuyuan/:id', require('./routes/novel/zhaishuyuan'));
|
||||
|
||||
// 中国气象网
|
||||
router.get('/weatheralarm', require('./routes/weatheralarm'));
|
||||
router.get('/weatheralarm/:province?', require('./routes/weatheralarm'));
|
||||
|
||||
// Gitlab
|
||||
router.get('/gitlab/explore/:type', require('./routes/gitlab/explore'));
|
||||
|
||||
@@ -1,23 +1,25 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const date = require('@/utils/date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const alarmInfoURL = 'http://www.nmc.cn/f/alarm.html';
|
||||
const html = (await got.get(alarmInfoURL)).data;
|
||||
const $ = cheerio.load(html);
|
||||
const alarmElements = $('.alarmlist > div:not(.pagination)').toArray();
|
||||
const province = encodeURIComponent(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: alarmInfoURL,
|
||||
item: alarmElements.map((el) => {
|
||||
const $el = $(el);
|
||||
const $aEl = $el.find('a');
|
||||
link: `http://www.nmc.cn/publish/alarm.html`,
|
||||
item: list.map((item) => {
|
||||
const title = item.title;
|
||||
const url = item.url;
|
||||
return {
|
||||
title: $aEl.text(),
|
||||
link: `http://www.nmc.cn${$aEl.attr('href')}`,
|
||||
pubDate: date($el.find('.date').text(), 8),
|
||||
title: `${title}`,
|
||||
link: `http://www.nmc.cn${url}`,
|
||||
pubDate: `${item.issuetime}`,
|
||||
};
|
||||
}),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user