From 8888da3fc5d61977015b768779b005c090bd8996 Mon Sep 17 00:00:00 2001 From: Wade Ying Date: Fri, 24 May 2019 17:52:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20aqicn.org=20=E5=AE=9E=E6=97=B6?= =?UTF-8?q?=E7=A9=BA=E6=B0=94=E8=B4=A8=E9=87=8F=20(#2209)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add aqicn.org 实时空气质量 * fix: 修正修改显示内容 --- docs/other.md | 6 ++++++ lib/router.js | 3 +++ lib/routes/aqicn/index.js | 27 +++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 lib/routes/aqicn/index.js diff --git a/docs/other.md b/docs/other.md index ab43a1a86..2bcbbf9f1 100644 --- a/docs/other.md +++ b/docs/other.md @@ -884,3 +884,9 @@ type 为 all 时,category 参数不支持 cost 和 free ### 全文 + +##空气质量 + +###实时 AQI + + diff --git a/lib/router.js b/lib/router.js index 2fa15ef5d..3cd677f56 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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; diff --git a/lib/routes/aqicn/index.js b/lib/routes/aqicn/index.js new file mode 100644 index 000000000..888144b10 --- /dev/null +++ b/lib/routes/aqicn/index.js @@ -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}
风力:${data.cwind[0]}
AQI:${data.aqi}
`, + pubDate: new Date(data.time * 1000).toUTCString(), + guid: data.time, + link: `https://aqicn.org/city/${data.ids.path}`, + }, + ], + }; +};