diff --git a/routes/weatherAlarm/gradeMapping.json b/routes/weatherAlarm/gradeMapping.json index 99a551a91..7ce916cd9 100644 --- a/routes/weatherAlarm/gradeMapping.json +++ b/routes/weatherAlarm/gradeMapping.json @@ -4,4 +4,4 @@ "03": "橙色", "04": "红色", "05": "白色" -} \ No newline at end of file +} diff --git a/routes/weatherAlarm/index.js b/routes/weatherAlarm/index.js index 284fa857b..40e370cd4 100644 --- a/routes/weatherAlarm/index.js +++ b/routes/weatherAlarm/index.js @@ -8,29 +8,29 @@ 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条数据 + 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 => ({ + 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 index 43732e496..0f3a233ae 100644 --- a/routes/weatherAlarm/typeMapping.json +++ b/routes/weatherAlarm/typeMapping.json @@ -44,4 +44,4 @@ "70": "海上雷电", "71": "海上台风", "72": "低温" -} \ No newline at end of file +}