mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-08 22:19:40 +08:00
feat: 丁香园肺炎路由支持城市查询 (#3838)
This commit is contained in:
@@ -404,7 +404,7 @@ type 为 all 时,category 参数不支持 cost 和 free
|
|||||||
|
|
||||||
### 丁香园 - 全国新型肺炎疫情数据统计
|
### 丁香园 - 全国新型肺炎疫情数据统计
|
||||||
|
|
||||||
<Route author="DIYgod HenryQW" example="/coronavirus/dxy/data/湖北" path="/coronavirus/dxy/data/:province?" :paramsDesc="['省份,缺省为全国']"/>
|
<Route author="DIYgod HenryQW" example="/coronavirus/dxy/data/湖北/武汉" path="/coronavirus/dxy/data/:province?/:city?" :paramsDesc="['省/直辖市名,缺省或错误则返回全国数据','城市名,缺省或错误则返回全省数据。直辖市请使用区/县名。']"/>
|
||||||
|
|
||||||
### South China Morning Post - China coronavirus outbreak
|
### South China Morning Post - China coronavirus outbreak
|
||||||
|
|
||||||
|
|||||||
@@ -2155,7 +2155,7 @@ router.get('/weixin/miniprogram/release', require('./routes/weixinMiniprogram/re
|
|||||||
|
|
||||||
// 武汉肺炎疫情动态
|
// 武汉肺炎疫情动态
|
||||||
router.get('/coronavirus/caixin', require('./routes/coronavirus/caixin'));
|
router.get('/coronavirus/caixin', require('./routes/coronavirus/caixin'));
|
||||||
router.get('/coronavirus/dxy/data/:province?', require('./routes/coronavirus/dxy-data'));
|
router.get('/coronavirus/dxy/data/:province?/:city?', require('./routes/coronavirus/dxy-data'));
|
||||||
router.get('/coronavirus/dxy', require('./routes/coronavirus/dxy'));
|
router.get('/coronavirus/dxy', require('./routes/coronavirus/dxy'));
|
||||||
router.get('/coronavirus/scmp', require('./routes/coronavirus/scmp'));
|
router.get('/coronavirus/scmp', require('./routes/coronavirus/scmp'));
|
||||||
router.get('/coronavirus/nhc', require('./routes/coronavirus/nhc'));
|
router.get('/coronavirus/nhc', require('./routes/coronavirus/nhc'));
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ const jsdom = require('jsdom');
|
|||||||
const { JSDOM } = jsdom;
|
const { JSDOM } = jsdom;
|
||||||
|
|
||||||
module.exports = async (ctx) => {
|
module.exports = async (ctx) => {
|
||||||
const province = ctx.params.province || '全国';
|
const PROVINCE = ctx.params.province || '全国';
|
||||||
|
let CITY = ctx.params.city || '';
|
||||||
|
|
||||||
const link = 'https://3g.dxy.cn/newh5/view/pneumonia';
|
const link = 'https://3g.dxy.cn/newh5/view/pneumonia';
|
||||||
|
|
||||||
@@ -18,39 +19,66 @@ module.exports = async (ctx) => {
|
|||||||
|
|
||||||
const item = {};
|
const item = {};
|
||||||
|
|
||||||
let meta;
|
let AREA, DATA, META;
|
||||||
|
|
||||||
if (province !== '全国') {
|
const getProvince = () => {
|
||||||
meta = dom.window.getListByCountryTypeService1.find((item) => item.provinceShortName === province);
|
AREA = PROVINCE;
|
||||||
|
DATA = dom.window.getAreaStat.find((item) => item.provinceShortName === PROVINCE);
|
||||||
|
|
||||||
const data = dom.window.getAreaStat.find((item) => item.provinceShortName === province);
|
if (!DATA) {
|
||||||
|
// 省份名不存在
|
||||||
if (data.cities) {
|
return getCountry();
|
||||||
item.description = '';
|
|
||||||
|
|
||||||
if (meta.tags) {
|
|
||||||
item.description += `最新更新:${meta.tags}。<br><br>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < data.cities.length; i++) {
|
|
||||||
const city = data.cities[i];
|
|
||||||
item.description += `${city.cityName}:确诊 ${city.confirmedCount} 例,死亡 ${city.deadCount} 例,治愈 ${city.curedCount} 例。<br><br>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
item.title = `${province}新型肺炎疫情数据:确诊 ${data.confirmedCount} 例,疑似 ${data.suspectedCount} 例,死亡 ${data.deadCount} 例,治愈 ${data.curedCount} 例`;
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
meta = dom.window.getStatisticsService;
|
|
||||||
|
|
||||||
item.title = `${province}确诊 ${meta.confirmedCount} 例,疑似 ${meta.suspectedCount} 例,死亡 ${meta.deadCount} 例,治愈 ${meta.curedCount} 例。`;
|
META = dom.window.getListByCountryTypeService1.find((item) => item.provinceShortName === PROVINCE);
|
||||||
|
|
||||||
|
if (CITY) {
|
||||||
|
return getCity();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (META.tags) {
|
||||||
|
item.description = `最近更新:${META.tags}。<br><br>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
DATA.cities.forEach((city) => {
|
||||||
|
item.description += `${city.cityName}:确诊 ${city.confirmedCount} 例,死亡 ${city.deadCount} 例,治愈 ${city.curedCount} 例。<br><br>`;
|
||||||
|
});
|
||||||
|
|
||||||
|
item.title = `${AREA}新型肺炎疫情数据:确诊 ${DATA.confirmedCount} 例,疑似 ${DATA.suspectedCount} 例,死亡 ${DATA.deadCount} 例,治愈 ${DATA.curedCount} 例`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getCity = () => {
|
||||||
|
AREA = CITY;
|
||||||
|
DATA = DATA.cities.find((c) => c.cityName.includes(CITY));
|
||||||
|
|
||||||
|
if (DATA) {
|
||||||
|
item.title = `${DATA.cityName}:确诊 ${DATA.confirmedCount} 例,死亡 ${DATA.deadCount} 例,治愈 ${DATA.curedCount} 例`;
|
||||||
|
} else {
|
||||||
|
// 城市不存在
|
||||||
|
CITY = '';
|
||||||
|
return getProvince();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getCountry = () => {
|
||||||
|
AREA = '全国';
|
||||||
|
META = dom.window.getStatisticsService;
|
||||||
|
|
||||||
|
item.title = `全国确诊 ${META.confirmedCount} 例,疑似 ${META.suspectedCount} 例,死亡 ${META.deadCount} 例,治愈 ${META.curedCount} 例。`;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (PROVINCE !== '全国') {
|
||||||
|
getProvince();
|
||||||
|
} else {
|
||||||
|
getCountry();
|
||||||
}
|
}
|
||||||
|
|
||||||
item.pubDate = new Date(meta.modifyTime).toUTCString();
|
item.pubDate = new Date(META.modifyTime).toUTCString();
|
||||||
item.link = link;
|
item.link = link;
|
||||||
item.guid = item.title;
|
item.guid = item.title;
|
||||||
|
|
||||||
ctx.state.data = {
|
ctx.state.data = {
|
||||||
title: `全国新型肺炎疫情数据统计(${province})-丁香园`,
|
title: `${AREA}新型肺炎疫情数据统计 - 丁香园`,
|
||||||
link,
|
link,
|
||||||
item: [item],
|
item: [item],
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user