From 8124d5f7517a8629d11505bf044de27b94443491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=A1=E5=B1=B1=E7=94=B5=E8=BD=A6?= Date: Fri, 24 Aug 2018 19:18:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AF=B9=E4=B8=AD=E5=9B=BD?= =?UTF-8?q?=E5=A4=A9=E6=B0=94=E7=BD=91=E5=85=A8=E5=9B=BD=E6=B0=94=E8=B1=A1?= =?UTF-8?q?=E9=A2=84=E8=AD=A6=E7=9A=84=E6=94=AF=E6=8C=81=20(#527)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ docs/README.md | 10 ++++++ router.js | 3 ++ routes/earthquake/index.js | 1 - routes/weatherAlarm/gradeMapping.json | 7 ++++ routes/weatherAlarm/index.js | 36 ++++++++++++++++++++ routes/weatherAlarm/typeMapping.json | 47 +++++++++++++++++++++++++++ 7 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 routes/weatherAlarm/gradeMapping.json create mode 100644 routes/weatherAlarm/index.js create mode 100644 routes/weatherAlarm/typeMapping.json diff --git a/README.md b/README.md index ea89a945bc..7d4e36d78b 100644 --- a/README.md +++ b/README.md @@ -254,6 +254,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 - 笔趣阁 - UU 看书 - 文学迷 +- 中国天气网 + - 全国气象预警 - Gitlab - Explore diff --git a/docs/README.md b/docs/README.md index c3c3dc62c2..12431069cd 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2078,6 +2078,16 @@ type,必选,目前支持两种,`hot` 代表热门游记,`latest` 代表 举例网址:https://www.wenxuemi.com/files/article/html/6/6144/ +### 中国气象网 + +#### 全国气象预警 + +举例: <(https://rsshub.app/weatherAlarm> + +路由: `/weatherAlarm` + +参数: 无(提示: 可以使用全局过滤参数订阅您感兴趣的地区的信息) + ## Gitlab ### Explore diff --git a/router.js b/router.js index 9730641678..ad6a9a94b8 100755 --- a/router.js +++ b/router.js @@ -454,6 +454,9 @@ router.get('/novel/biquge/:id', require('./routes/novel/biquge')); router.get('/novel/uukanshu/:uid', require('./routes/novel/uukanshu')); router.get('/novel/wenxuemi/:id1/:id2', require('./routes/novel/wenxuemi')); +// 中国气象网 +router.get('/weatherAlarm', require('./routes/weatherAlarm')); + // Gitlab router.get('/gitlab/explore/:type', require('./routes/gitlab/explore')); diff --git a/routes/earthquake/index.js b/routes/earthquake/index.js index ed86b2c97f..57aa3af721 100644 --- a/routes/earthquake/index.js +++ b/routes/earthquake/index.js @@ -64,7 +64,6 @@ module.exports = async (ctx) => { .text() .trim() .substring(5); - console.log($container.html()); return { title: $el.find('a').text(), diff --git a/routes/weatherAlarm/gradeMapping.json b/routes/weatherAlarm/gradeMapping.json new file mode 100644 index 0000000000..99a551a915 --- /dev/null +++ b/routes/weatherAlarm/gradeMapping.json @@ -0,0 +1,7 @@ +{ + "01": "蓝色", + "02": "黄色", + "03": "橙色", + "04": "红色", + "05": "白色" +} \ No newline at end of file diff --git a/routes/weatherAlarm/index.js b/routes/weatherAlarm/index.js new file mode 100644 index 0000000000..284fa857ba --- /dev/null +++ b/routes/weatherAlarm/index.js @@ -0,0 +1,36 @@ +const axios = require('../../utils/axios'); +const DateTime = require('luxon').DateTime; + +// 映射信息复制自网页的JS代码 http://i.tq121.com.cn/j/data_alarm.js +const gradeMap = require('./gradeMapping.json'); +const typeMap = require('./typeMapping.json'); + +module.exports = async (ctx) => { + const alarmInfoURL = `http://product.weather.com.cn/alarm/grepalarm_cn.php?_=${Date.now()}`; + const jsonString = (await axios.get(alarmInfoURL)).data.slice(14, -1); + const alaramData = JSON.parse(jsonString).data + .map((pair) => { + const location = pair[0]; + const list = pair[1].slice(0, -5).split('-'); + const date = DateTime.fromFormat(list[1], 'yyyyMMddhhmmss'); + const gradeCode = list[2].slice(2); + const typeCode = list[2].slice(0, 2); + return { + location, + date, + grade: gradeMap[gradeCode], + type: typeMap[typeCode], + link: `http://www.weather.com.cn/alarm/newalarmcontent.shtml?file=${pair[1]}`, + }; + }) + .slice(0, 30) // 取最新的30条数据 + ctx.state.data = { + title: '中国天气网气象预警', + link: 'http://www.weather.com.cn/alarm/', + item: alaramData.map(item => ({ + title: `${item.location}${item.date.toFormat('M月dd日HH时mm分')}发布${item.grade}${item.type}预警`, + link: item.link, + pubDate: item.date.toRFC2822(), + })), + }; +}; \ No newline at end of file diff --git a/routes/weatherAlarm/typeMapping.json b/routes/weatherAlarm/typeMapping.json new file mode 100644 index 0000000000..43732e4968 --- /dev/null +++ b/routes/weatherAlarm/typeMapping.json @@ -0,0 +1,47 @@ +{ + "01": "台风", + "02": "暴雨", + "03": "暴雪", + "04": "寒潮", + "05": "大风", + "06": "沙尘暴", + "07": "高温", + "08": "干旱", + "09": "雷电", + "10": "冰雹", + "11": "霜冻", + "12": "大雾", + "13": "霾", + "14": "道路结冰", + "91": "寒冷", + "92": "灰霾", + "93": "雷雨大风", + "94": "森林火险", + "95": "降温", + "96": "道路冰雪", + "97": "干热风", + "98": "空气重污染", + "99": "低温", + "51": "海上大雾", + "52": "雷暴大风", + "53": "持续低温", + "54": "浓浮尘", + "55": "龙卷风", + "56": "低温冻害", + "57": "海上大风", + "58": "低温雨雪冰冻", + "59": "强对流", + "60": "臭氧", + "61": "大雪", + "62": "强降雨", + "63": "强降温", + "64": "雪灾", + "65": "森林(草原)火险", + "66": "雷暴", + "67": "严寒", + "68": "沙尘", + "69": "海上雷雨大风", + "70": "海上雷电", + "71": "海上台风", + "72": "低温" +} \ No newline at end of file