Files
RSSHub/lib/v2/earthquake/index.js
T
b0ttle f477e3e8bf fix(route): fixed routes/earthquake and ceic timezone shift (#9780)
* fixed routes/earthquake and ceic timezone shift

* use utils/timezone and remove changes on yarn.lock

* edit format problem

* refactor: migrate to v2
2022-05-19 01:29:58 +08:00

41 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
module.exports = async (ctx) => {
const region = ctx.params.region ?? 1;
const api = 'https://www.cea.gov.cn/eportal/ui?struts.portlet.mode=view&struts.portlet.action=/portlet/expressEarthquake!queryExpressEarthquakeList.action&pageId=363409&moduleId=a852ba487b534470a84a30f00e7d6670';
const link = 'https://www.cea.gov.cn/cea/xwzx/zqsd/index.html';
const response = await got({
method: 'post',
url: api,
form: {
region,
dateType: 2,
magnitude: 0,
},
});
const data = response.data;
const out = data.map((item) => {
const { id, epicenter, latitudes, longitudes, depth } = item;
const date = item.orig_time;
const num = item.num_mag;
const description = `北京时间${date},${epicenter}(纬度${latitudes}度,经度${longitudes}度)发生${num}级地震,震源深度${depth}千米`;
return {
title: `${epicenter}发生${num}级地震`,
link: `https://www.cea.gov.cn/eportal/ui?struts.portlet.mode=view&struts.portlet.action=/portlet/expressEarthquake!toNewInfoView.action&pageId=366521&id=${id}`,
pubDate: timezone(parseDate(date, 'YYYY-MM-DD HH:mm:ss'), +8),
description,
};
});
ctx.state.data = {
title: '中国地震局震情速递',
link,
item: out,
};
};