feat(route) add qweather/now (#9413)
* qweather_now * now * pubDate fix * timezone * parseDate
This commit is contained in:
parent
95db3b4e99
commit
0a29a7c4e8
|
|
@ -62,12 +62,19 @@ pageClass: routes
|
|||
|
||||
### 近三天天气
|
||||
|
||||
<Route author="Rein-Ou" example="/qweather/广州" path="/qweather/:location" selfhost="1">
|
||||
<Route author="Rein-Ou" example="/qweather/3days/广州" path="/qweather/3days/:location" selfhost="1">
|
||||
|
||||
需自行注册获取 api 的 key,并在环境变量 HEFENG_KEY 中进行配置,获取订阅近三天天气预报
|
||||
|
||||
</Route>
|
||||
|
||||
### 实时天气
|
||||
<Route author="Rein-Ou" example="/qweather/广州" path="/qweather/now/:location" selfhost="1">
|
||||
|
||||
需自行注册获取api的key,每小时更新一次数据
|
||||
|
||||
</Route>
|
||||
|
||||
## 上海市生态环境局
|
||||
|
||||
### 空气质量
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ module.exports = async (ctx) => {
|
|||
}
|
||||
const items = data.map((item) => ({
|
||||
title: '预报日期:' + item.fxDate,
|
||||
description: art(path.join(__dirname, './util/weather.art'), {
|
||||
description: art(path.join(__dirname, './util/3days.art'), {
|
||||
item,
|
||||
}),
|
||||
pubDate: responseData.updateTime,
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = {
|
||||
'/weather/:location': ['Rein-Ou'],
|
||||
'/qweather/3days/:location': ['Rein-Ou'],
|
||||
'/qweather/now/:location': ['Rein-Ou'],
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
const got = require('@/utils/got');
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const config = require('@/config').value;
|
||||
const rootUrl = 'https://devapi.qweather.com/v7/weather/now?';
|
||||
module.exports = async (ctx) => {
|
||||
const id = await ctx.cache.tryGet(ctx.params.location + '_id', async () => {
|
||||
const response = await got(`https://geoapi.qweather.com/v2/city/lookup?location=${ctx.params.location}&key=${config.hefeng.key}`);
|
||||
const data = [];
|
||||
for (const i in response.data.location) {
|
||||
data.push(response.data.location[i]);
|
||||
}
|
||||
return data[0].id;
|
||||
});
|
||||
const requestUrl = rootUrl + 'key=' + config.hefeng.key + '&location=' + id;
|
||||
const responseData = await ctx.cache.tryGet(
|
||||
ctx.params.location,
|
||||
async () => {
|
||||
const response = await got(requestUrl);
|
||||
return response.data;
|
||||
},
|
||||
3600, // second
|
||||
false
|
||||
);
|
||||
|
||||
const data = [responseData.now];
|
||||
|
||||
ctx.state.data = {
|
||||
title: ctx.params.location + '实时天气',
|
||||
description: ctx.params.location + '实时天气状况',
|
||||
item: data.map((item) => ({
|
||||
title: '观测时间:' + parseDate(responseData.updateTime),
|
||||
description: art(path.join(__dirname, './util/now.art'), { item }),
|
||||
pubDate: parseDate(responseData.updateTime),
|
||||
guid: '位置:' + ctx.params.location + '--时间:' + parseDate(responseData.updateTime),
|
||||
link: item.fxLink,
|
||||
})),
|
||||
link: responseData.fxLink,
|
||||
};
|
||||
};
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/:location', require('./index'));
|
||||
router.get('/3days/:location', require('./3days'));
|
||||
router.get('/now/:location', require('./now'));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
<text>天气:{{item.text}}</text>
|
||||
<br>
|
||||
<text>气温:{{item.temp}}</text>
|
||||
<br>
|
||||
<text>体感温度:{{item.feelsLike}}</text>
|
||||
<br>
|
||||
<text>风向:{{item.windDir}}</text>
|
||||
<br>
|
||||
<text>风力:{{item.windScale}} 风速:{{item.windSpeed}}公里</text>
|
||||
<br>
|
||||
<text>湿度:{{item.humidity}}% 大气压强:{{item.pressure}}百帕</text>
|
||||
<br>
|
||||
<text>本小时降水量:{{item.precip}}</text>
|
||||
<br>
|
||||
<text>能见度:{{item.vis}}公里</text>
|
||||
<br>
|
||||
Loading…
Reference in New Issue