diff --git a/docs/forecast.md b/docs/forecast.md index 60cc20eaf0..33f0e1821c 100644 --- a/docs/forecast.md +++ b/docs/forecast.md @@ -4,6 +4,24 @@ pageClass: routes # 预报预警 +## 地震速报 + +### 中国地震局 + + + +可通过全局过滤参数订阅您感兴趣的地区. + + + +### 中国地震台 + + + +可通过全局过滤参数订阅您感兴趣的地区. + + + ## 停电通知 获取未来一天的停电通知 @@ -70,16 +88,6 @@ pageClass: routes -## 中国地震局 - -### 地震速报 - - - -可通过全局过滤参数订阅您感兴趣的地区. - - - ## 中央气象台 ### 全国气象预警 diff --git a/lib/router.js b/lib/router.js index 833a29feb1..4943eca0f6 100644 --- a/lib/router.js +++ b/lib/router.js @@ -484,6 +484,9 @@ router.get('/mafengwo/note/:type', require('./routes/mafengwo/note')); // 中国地震局震情速递(与地震台网同步更新) router.get('/earthquake/:region?', require('./routes/earthquake')); +// 中国地震台网 +router.get('/earthquake/ceic/:type', require('./routes/earthquake/ceic')); + // 笔趣阁 router.get('/biquge/novel/latestchapter/:id', require('./routes/novel/biquge')); diff --git a/lib/routes/earthquake/ceic.js b/lib/routes/earthquake/ceic.js new file mode 100644 index 0000000000..814f0cdb27 --- /dev/null +++ b/lib/routes/earthquake/ceic.js @@ -0,0 +1,65 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + let type = Number(ctx.params.type); + type = type ? type : 1; + const baseUrl = 'http://www.ceic.ac.cn'; + const api = `${baseUrl}/ajax/speedsearch?num=${type}`; + const mappings = { + O_TIME: '发震时刻(UTC+8)', + LOCATION_C: '参考位置', + M: '震级(M)', + EPI_LAT: '纬度(°)', + EPI_LON: '经度(°)', + EPI_DEPTH: '深度(千米)', + SAVE_TIME: '录入时间', + }; + + const typeMappings = { + 1: '最近24小时地震信息', + 2: '最近48小时地震信息', + 3: '最近7天地震信息', + 4: '最近30天地震信息', + 5: '最近一年3.0级以上地震信息', + 6: '最近一年地震信息', + 7: '最近一年3.0级以下地震', + 8: '最近一年4.0级以上地震信息', + 9: '最近一年5.0级以上地震信息', + 0: '最近一年6.0级以上地震信息', + }; + + // 因为item数量限制20,所以对于RSS来说为无用类型,防止浪费资源 + const disabledType = [3, 4, 6]; + + if (disabledType.includes(type)) { + type = 1; + } + const typeName = typeMappings[type]; + + const response = await got(api); + const data = response.data; + let json = JSON.parse(data.substring(1, data.length - 1)).shuju; + if (json.length > 20) { + json = json.slice(0, 20); + } + + ctx.state.data = { + title: typeName, + link: `${baseUrl}/speedsearch`, + item: json.map((entity) => { + const contentBuilder = []; + const { NEW_DID } = entity; + for (const mappingsKey in mappings) { + contentBuilder.push(`${mappings[mappingsKey]} ${entity[mappingsKey]}`); + } + + return { + title: `${entity.LOCATION_C}发生${entity.M}级地震`, + link: `${baseUrl}/${NEW_DID}.html`, + pubDate: new Date(entity.O_TIME).toUTCString(), + description: contentBuilder.join('
'), + guid: NEW_DID, + }; + }), + }; +}; diff --git a/lib/routes/earthquake/index.js b/lib/routes/earthquake/index.js index 5c5a6ce992..6f76cd1d5d 100644 --- a/lib/routes/earthquake/index.js +++ b/lib/routes/earthquake/index.js @@ -19,13 +19,9 @@ module.exports = async (ctx) => { const out = await Promise.all( data.map(async (item) => { - const id = item.id; - const epicenter = item.epicenter; + const { id, epicenter, latitudes, longitudes, depth } = item; const date = item.orig_time.slice(0, -2); const num = item.num_mag; - const latitudes = item.latitudes; - const longitudes = item.longitudes; - const depth = item.depth; const description = `北京时间${date},${epicenter}(纬度${latitudes}度,经度${longitudes}度)发生${num}级地震,震源深度${depth}千米`; const single = { diff --git a/package.json b/package.json index 122fa38088..95fbc3c4a1 100644 --- a/package.json +++ b/package.json @@ -118,4 +118,4 @@ "_moduleAliases": { "@": "./lib" } -} \ No newline at end of file +}