feat: aqicn 显示更详细的空气污染成分
Signed-off-by: hang333 <jonathan.goh333@gmail.com>
This commit is contained in:
parent
6676fefe1a
commit
4cd0f4a282
|
|
@ -378,7 +378,21 @@ type 为 all 时,category 参数不支持 cost 和 free
|
|||
|
||||
### 实时 AQI
|
||||
|
||||
<Route author="xapool" example="/aqicn/beijing" path="/aqicn/:city" :paramsDesc="['城市拼音或地区 ID,详见[aqicn.org](http://aqicn.org/city/)']"/>
|
||||
<Route author="xapool" example="/aqicn/beijing/pm25,pm10" path="/aqicn/:city/:pollution?" :paramsDesc="['城市拼音或地区 ID,详见[aqicn.org](http://aqicn.org/city/)', '可选择显示更详细的空气污染成分']"/>
|
||||
|
||||
| 参数 | 污染成分 |
|
||||
| -------- | -------- |
|
||||
| pm25 | PM2.5 |
|
||||
| pm10 | PM10 |
|
||||
| o3 | O3 |
|
||||
| no2 | NO2 |
|
||||
| so2 | SO2 |
|
||||
| co | CO |
|
||||
|
||||
举例: [https://rsshub.app/aqicn/beijing/pm25,pm10](https://rsshub.app/aqicn/beijing/pm25.pm10)
|
||||
|
||||
1. 显示单个污染成分,例如「pm25」, [https://rsshub.app/aqicn/beijing/pm25](https://rsshub.app/aqicn/beijing/pm25)
|
||||
2. 逗号分隔显示多个污染成分,例如「pm25,pm10」,[https://rsshub.app/aqicn/beijing/pm25,pm10](https://rsshub.app/aqicn/beijing/pm25.pm10)
|
||||
|
||||
## 酷安
|
||||
|
||||
|
|
|
|||
|
|
@ -1711,7 +1711,7 @@ router.get('/aeon/:cid', require('./routes/aeon/category'));
|
|||
router.get('/algocasts', require('./routes/algocasts/all'));
|
||||
|
||||
// aqicn
|
||||
router.get('/aqicn/:city', require('./routes/aqicn/index'));
|
||||
router.get('/aqicn/:city/:pollution?', require('./routes/aqicn/index'));
|
||||
|
||||
// 猫眼电影
|
||||
router.get('/maoyan/hot', require('./routes/maoyan/hot'));
|
||||
|
|
|
|||
|
|
@ -2,6 +2,15 @@ const got = require('@/utils/got');
|
|||
|
||||
module.exports = async (ctx) => {
|
||||
const city = ctx.params.city;
|
||||
const pollution = ctx.params.pollution || [];
|
||||
const pollutionType = {
|
||||
so2: 'so2',
|
||||
no2: 'no2',
|
||||
co: 'co',
|
||||
o3: 'O3',
|
||||
pm25: 'PM2.5',
|
||||
pm10: 'PM10',
|
||||
};
|
||||
const area = isNaN(city) ? city : `@${city}`;
|
||||
|
||||
const response = await got({
|
||||
|
|
@ -10,6 +19,16 @@ module.exports = async (ctx) => {
|
|||
});
|
||||
const data = response.data;
|
||||
|
||||
const pollutionDetailed =
|
||||
pollution.length === 0
|
||||
? ''
|
||||
: pollution.split(',').reduce((result, item) => {
|
||||
result += `${pollutionType[item].toUpperCase()}:<b>${
|
||||
typeof data.historic[pollutionType[item]] === 'object' ? data.historic[pollutionType[item]][Object.keys(data.historic[pollutionType[item]])[0]] : data.historic[pollutionType[item]][0]
|
||||
}</b><br>`;
|
||||
return result;
|
||||
}, '');
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${data.namena}AQI`,
|
||||
link: `https://aqicn.org/city/${data.ids.path}`,
|
||||
|
|
@ -17,7 +36,7 @@ module.exports = async (ctx) => {
|
|||
item: [
|
||||
{
|
||||
title: `${data.namena}实时空气质量(AQI)${data.utimecn}`,
|
||||
description: `${data.infocn}<br>风力:<b>${data.cwind[0]}</b>级<br>AQI:<b>${data.aqi}</b><br><img src="${data.wgt}">`,
|
||||
description: `${data.infocn}<br>风力:<b>${data.cwind[0]}</b>级<br>AQI:<b>${data.aqi}</b><br>${pollutionDetailed}<img src="${data.wgt}">`,
|
||||
pubDate: new Date(data.time * 1000).toUTCString(),
|
||||
guid: data.time,
|
||||
link: `https://aqicn.org/city/${data.ids.path}`,
|
||||
|
|
|
|||
Loading…
Reference in New Issue