forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
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 Weather forcast (DIYgod#9382)
* weather_forcast * format * cache * Update lib/v2/weather/index.js Co-authored-by: Tony <[email protected]> * Update lib/v2/weather/util/location.js Co-authored-by: Tony <[email protected]> * Update docs/forecast.md Co-authored-by: Tony <[email protected]> * modify * Update forecast.md * readme.md * docs: reorder `HEFENG_KEY`
- Loading branch information
Showing
8 changed files
with
83 additions
and
1 deletion.
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
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,37 @@ | ||
const got = require('@/utils/got'); | ||
const { art } = require('@/utils/render'); | ||
const path = require('path'); | ||
const config = require('@/config').value; | ||
const rootUrl = 'https://devapi.qweather.com/v7/weather/3d?'; | ||
|
||
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); | ||
// console.log(response.data); | ||
return response.data; | ||
}); | ||
const data = []; | ||
for (const i in responseData.daily) { | ||
data.push(responseData.daily[i]); | ||
} | ||
const items = data.map((item) => ({ | ||
title: '预报日期:' + item.fxDate, | ||
description: art(path.join(__dirname, './util/weather.art'), { | ||
item, | ||
}), | ||
})); | ||
|
||
ctx.state.data = { | ||
title: ctx.params.location + '未来三天天气', | ||
item: items, | ||
}; | ||
}; |
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,3 @@ | ||
module.exports = { | ||
'/weather/: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,3 @@ | ||
module.exports = function (router) { | ||
router.get('/:location', require('./index')); | ||
}; |
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,21 @@ | ||
<text>白天:{{item.textDay}}——夜间:{{item.textNight}}</text> | ||
<br> | ||
<text>气温:{{item.tempMin}}℃~{{item.tempMax}}℃</text> | ||
<br> | ||
<text>相对湿度:{{item.humidity}}(%)</text> | ||
<br> | ||
<text>大气压强:{{item.pressure}}(百帕)</text> | ||
<br> | ||
<text>紫外线强度:{{item.uvIndex}}</text> | ||
<br> | ||
<text>白天风向:{{item.windDirDay}};风力:{{item.windScaleDay}}级;风速:{{item.windSpeedDay}}公里/小时</text> | ||
<br> | ||
<text>夜间风向:{{item.windDirNight}};风力:{{item.windScaleNight}}级;风速:{{item.windSpeedNight}}公里/小时</text> | ||
<br> | ||
<text>能见度:{{item.vis}}(公里)</text> | ||
<br> | ||
<text>日出:{{item.sunrise}}&日落: {{item.sunset}}</text> | ||
<br> | ||
<text>月相:{{item.moonPhase}}&月出:{{item.sunrise}}&月落:{{item.moonset}} | ||
<br> | ||
|
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