diff --git a/docs/forecast.md b/docs/forecast.md index a38bd4069..4d599348c 100644 --- a/docs/forecast.md +++ b/docs/forecast.md @@ -22,6 +22,16 @@ pageClass: routes +## 国家应急广播网 + +### 预警信息 + + + +### 国内新闻 + + + ## 停电通知 获取未来一天的停电通知 diff --git a/lib/router.js b/lib/router.js index f6e43e796..0cdea8fae 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1646,4 +1646,8 @@ router.get('/sse/convert/:query?', require('./routes/sse/convert')); // 前端艺术家每日整理&&飞冰早报 router.get('/jskou/:type?', require('./routes/jskou/index')); +// 国家应急广播 +router.get('/cneb/yjxx', require('./routes/cneb/yjxx')); +router.get('/cneb/guoneinews', require('./routes/cneb/guoneinews')); + module.exports = router; diff --git a/lib/routes/cneb/guoneinews.js b/lib/routes/cneb/guoneinews.js new file mode 100644 index 000000000..8533183de --- /dev/null +++ b/lib/routes/cneb/guoneinews.js @@ -0,0 +1,25 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const list = (await got({ + method: 'get', + url: 'http://www.cneb.gov.cn/guoneinews/guoneidata/', + })).data.rollData; + + const items = list.map((item) => { + const single = { + title: item.title, + description: item.description.replace(//g, ''), + pubDate: new Date(item.dateTime + ' UTC+08:00').toString(), + link: item.url, + }; + return single; + }); + + ctx.state.data = { + title: '国内新闻_国家应急广播网', + link: 'http://www.cneb.gov.cn/guoneinews/', + description: '国家应急广播', + item: items, + }; +}; diff --git a/lib/routes/cneb/yjxx.js b/lib/routes/cneb/yjxx.js new file mode 100644 index 000000000..177e37d16 --- /dev/null +++ b/lib/routes/cneb/yjxx.js @@ -0,0 +1,34 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const warningMessagesJsonp = (await got({ + method: 'get', + url: 'http://uc.cneb.gov.cn:8080/getWarningMessages?callback=func&start=0&pagetype=PAGE1409368873582889&rows=100&_=' + +new Date(), + })).data.trim(); + + let warningMessages = []; + + try { + const jsonString = warningMessagesJsonp.slice(5, -1); + warningMessages = JSON.parse(jsonString).docs; + } catch (error) { + // console.error(error); + } + + const items = warningMessages.map((item) => { + const single = { + title: item.brief, + description: item.content, + pubDate: new Date(item.publishdate + ' UTC+08:00').toString(), + link: item.url, + }; + return single; + }); + + ctx.state.data = { + title: '预警信息_国家应急广播网', + link: 'http://www.cneb.gov.cn/yjxx/', + description: '国家应急广播', + item: items, + }; +};