From 5c3ff7bf63cc9f7d058a38c3cc61cb9de0fda579 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Tue, 7 Jul 2020 17:15:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E5=9B=BD=E5=AE=B6=E9=A2=84?= =?UTF-8?q?=E8=AD=A6=E4=BF=A1=E6=81=AF=E5=8F=91=E5=B8=83=E4=B8=AD=E5=BF=83?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E7=94=9F=E6=95=88=E9=A2=84=E8=AD=A6=20(#5118?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/forecast.md | 6 ++++++ lib/router.js | 3 +++ lib/routes/12379/index.js | 23 +++++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 lib/routes/12379/index.js diff --git a/docs/forecast.md b/docs/forecast.md index 32f74aeaa0..684fb280a9 100644 --- a/docs/forecast.md +++ b/docs/forecast.md @@ -32,6 +32,12 @@ pageClass: routes +## 国家突发事件预警信息发布网 + +### 当前生效预警 + + + ## 国家应急广播网 ### 预警信息 diff --git a/lib/router.js b/lib/router.js index 8e69d0aa07..d74aa19173 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2932,4 +2932,7 @@ router.get('/gelonghui/keyword/:keyword', require('./routes/gelonghui/keyword')) // 光谷社区 router.get('/guanggoo/:caty', require('./routes/guanggoo/index')); +// 国家突发事件预警信息发布网 +router.get('/12379', require('./routes/12379/index')); + module.exports = router; diff --git a/lib/routes/12379/index.js b/lib/routes/12379/index.js new file mode 100644 index 0000000000..f4ed76fc83 --- /dev/null +++ b/lib/routes/12379/index.js @@ -0,0 +1,23 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const currentUrl = `http://www.12379.cn/data/index_map_all.html`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + const data = JSON.parse(response.data.substr('var alertData ='.length, response.data.length + 1)); + + const list = data.map((item) => ({ + title: item.headline, + link: `http://www.12379.cn/html/new2018/alarmcontent.shtml?file=${item.identifier}.html}`, + description: item.description, + pubDate: new Date(item.sendTime).toUTCString(), + })); + + ctx.state.data = { + title: `当前生效预警 - 国家突发事件预警信息发布网`, + link: currentUrl, + item: list, + }; +};