-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route) add qweather/now (#9413)
* qweather_now * now * pubDate fix * timezone * parseDate
- Loading branch information
Showing
7 changed files
with
70 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
module.exports = { | ||
'/weather/:location': ['Rein-Ou'], | ||
'/qweather/3days/:location': ['Rein-Ou'], | ||
'/qweather/now/:location': ['Rein-Ou'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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')); | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |