format
This commit is contained in:
parent
8124d5f751
commit
e1ed87945b
|
|
@ -4,4 +4,4 @@
|
|||
"03": "橙色",
|
||||
"04": "红色",
|
||||
"05": "白色"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
})),
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -44,4 +44,4 @@
|
|||
"70": "海上雷电",
|
||||
"71": "海上台风",
|
||||
"72": "低温"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue