feature: ceic (#2524)

* Fix the scripts run in Windows

* Feature: 中国地震台

* 添加item数量限制

* 添加类型检查

* Add doc

* Revert
This commit is contained in:
SettingDust
2019-07-03 11:56:52 +08:00
committed by DIYgod
parent 31b7f32b06
commit 01c22cee07
5 changed files with 88 additions and 16 deletions

View File

@@ -4,6 +4,24 @@ pageClass: routes
# 预报预警 # 预报预警
## 地震速报
### 中国地震局
<Route author="LogicJake" example="/earthquake" path="/earthquake/:region?" :paramsDesc="['区域0全部1国内默认2国外']" crawlerBadge="1">
可通过全局过滤参数订阅您感兴趣的地区.
</Route>
### 中国地震台
<Route author="SettingDust" example="/earthquake/ceic/1" path="/earthquake/ceic/:type" :paramsDesc="['类型1 最近24小时地震信息, 2: 最近48小时地震信息, 5: 最近一年3.0级以上地震信息, 7: 最近一年3.0级以下地震, 8: 最近一年4.0级以上地震信息, 9: 最近一年5.0级以上地震信息, 0: 最近一年6.0级以上地震信息']">
可通过全局过滤参数订阅您感兴趣的地区.
</Route>
## 停电通知 ## 停电通知
获取未来一天的停电通知 获取未来一天的停电通知
@@ -70,16 +88,6 @@ pageClass: routes
</Route> </Route>
## 中国地震局
### 地震速报
<Route author="LogicJake" example="/earthquake" path="/earthquake/:region?" :paramsDesc="['区域0全部1国内默认2国外']" crawlerBadge="1">
可通过全局过滤参数订阅您感兴趣的地区.
</Route>
## 中央气象台 ## 中央气象台
### 全国气象预警 ### 全国气象预警

View File

@@ -484,6 +484,9 @@ router.get('/mafengwo/note/:type', require('./routes/mafengwo/note'));
// 中国地震局震情速递(与地震台网同步更新) // 中国地震局震情速递(与地震台网同步更新)
router.get('/earthquake/:region?', require('./routes/earthquake')); 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')); router.get('/biquge/novel/latestchapter/:id', require('./routes/novel/biquge'));

View File

@@ -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('<br>'),
guid: NEW_DID,
};
}),
};
};

View File

@@ -19,13 +19,9 @@ module.exports = async (ctx) => {
const out = await Promise.all( const out = await Promise.all(
data.map(async (item) => { data.map(async (item) => {
const id = item.id; const { id, epicenter, latitudes, longitudes, depth } = item;
const epicenter = item.epicenter;
const date = item.orig_time.slice(0, -2); const date = item.orig_time.slice(0, -2);
const num = item.num_mag; 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 description = `北京时间${date}${epicenter}(纬度${latitudes}度,经度${longitudes}度)发生${num}级地震,震源深度${depth}千米`;
const single = { const single = {