feat: add aqicn.org 实时空气质量 (#2209)

* feat: add aqicn.org 实时空气质量

* fix: 修正修改显示内容
This commit is contained in:
Wade Ying 2019-05-24 17:52:04 +08:00 committed by DIYgod
parent e895dcf05a
commit 8888da3fc5
3 changed files with 36 additions and 0 deletions

View File

@ -884,3 +884,9 @@ type 为 all 时category 参数不支持 cost 和 free
### 全文
<Route author="HenryQW" example="/zzz" path="/zzz/index"/>
##空气质量
###实时 AQI
<Route author="xapool" example="/aqicn/beijing" path="/aqicn/:city" :paramsDesc="['城市拼音,详见[aqicn.org](http://aqicn.org/city/)']"/>

View File

@ -1341,4 +1341,7 @@ router.get('/steamgifts/discussions/:category?', require('./routes/steamgifts/di
// Steamgifts
router.get('/zzz', require('./routes/zzz/index'));
// aqicn
router.get('/aqicn/:city', require('./routes/aqicn/index'));
module.exports = router;

27
lib/routes/aqicn/index.js Normal file
View File

@ -0,0 +1,27 @@
const axios = require('@/utils/axios');
module.exports = async (ctx) => {
const city = ctx.params.city;
const area = isNaN(city) ? city : `@${city}`;
const response = await axios({
method: 'get',
url: `http://aqicn.org/aqicn/json/android/${area}/json`,
});
const data = response.data;
ctx.state.data = {
title: `${data.namena}AQI`,
link: `https://aqicn.org/city/${data.ids.path}`,
description: `${data.namena}AQI-aqicn.org`,
item: [
{
title: `${data.namena}实时空气质量(AQI)${data.utimecn}`,
description: `${data.infocn}<br>风力:<b>${data.cwind[0]}</b>级<br>AQI:<b>${data.aqi}</b><br><img referrerpolicy="no-referrer" src="${data.wgt}">`,
pubDate: new Date(data.time * 1000).toUTCString(),
guid: data.time,
link: `https://aqicn.org/city/${data.ids.path}`,
},
],
};
};