Skip to content

Commit

Permalink
fix(route): Weather forcast (DIYgod#9390)
Browse files Browse the repository at this point in the history
* weather_forcast

* format

* cache

* Update lib/v2/weather/index.js

* Update lib/v2/weather/util/location.js

* Update docs/forecast.md

* modify

* Update forecast.md

* readme.md

* docs: reorder `HEFENG_KEY`

* fixed cache problem

* dependent fix

* add link

* Update index.js

* fix dependent

* index

* fix md doc
  • Loading branch information
Rein-Ou authored and RikkaBlue committed Apr 9, 2022
1 parent 78dc9eb commit c0f74d1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 26 deletions.
20 changes: 10 additions & 10 deletions docs/forecast.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,6 @@ pageClass: routes

<Route author="muzea" example="/cneb/guoneinews" path="/cneb/guoneinews"/>

## 和风天气

### 近三天天气

<Route author="Rein-Ou" example="/weather/广州" path="/weather/:location" selfhost="1">

需自行注册获取和风天气 api 的 key,并在环境变量 HEFENG_KEY 中进行配置,获取订阅近三天天气预报

</Route>

## 上海市生态环境局

### 空气质量
Expand Down Expand Up @@ -139,3 +129,13 @@ pageClass: routes
可通过全局过滤参数订阅您感兴趣的地区.

</Route>

## 和风天气

### 近三天天气

<Route author="Rein-Ou" example="/weather/广州" path="/weather/:location" selfhost="1">

需自行注册获取 api 的 key,并在环境变量 HEFENG_KEY 中进行配置,获取订阅近三天天气预报

</Route>
19 changes: 14 additions & 5 deletions lib/v2/weather/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ module.exports = async (ctx) => {
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 responseData = await ctx.cache.tryGet(
ctx.params.location,
async () => {
const response = await got(requestUrl);
return response.data;
},
config.cache.contentExpire,
false
);
const data = [];
for (const i in responseData.daily) {
data.push(responseData.daily[i]);
Expand All @@ -28,10 +32,15 @@ module.exports = async (ctx) => {
description: art(path.join(__dirname, './util/weather.art'), {
item,
}),
pubDate: responseData.updateTime,
guid: '位置:' + ctx.params.location + '--日期:' + item.fxDate,
link: responseData.fxLink,
}));

ctx.state.data = {
title: ctx.params.location + '未来三天天气',
description: ctx.params.location + '未来三天天气情况,使用和风彩云api',
item: items,
link: responseData.fxLink,
};
};
17 changes: 8 additions & 9 deletions lib/v2/weather/util/weather.art
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@
<br>
<text>气温:{{item.tempMin}}℃~{{item.tempMax}}℃</text>
<br>
<text>相对湿度:{{item.humidity}}(%)</text>
<text>相对湿度:{{item.humidity}}%</text>
<br>
<text>大气压强:{{item.pressure}}(百帕)</text>
<text>大气压强:{{item.pressure}}百帕</text>
<br>
<text>紫外线强度:{{item.uvIndex}}</text>
<br>
<text>白天风向:{{item.windDirDay}}风力:{{item.windScaleDay}}级风速:{{item.windSpeedDay}}公里/小时</text>
<text>白天风向:{{item.windDirDay}} 风力:{{item.windScaleDay}}级 风速:{{item.windSpeedDay}}公里/小时</text>
<br>
<text>夜间风向:{{item.windDirNight}}风力:{{item.windScaleNight}}级风速:{{item.windSpeedNight}}公里/小时</text>
<text>夜间风向:{{item.windDirNight}} 风力:{{item.windScaleNight}}级 风速:{{item.windSpeedNight}}公里/小时</text>
<br>
<text>能见度:{{item.vis}}(公里)</text>
<text>能见度:{{item.vis}}公里</text>
<br>
<text>日出:{{item.sunrise}}&日落: {{item.sunset}}</text>
<text>日出:{{item.sunrise}} 日落: {{item.sunset}}</text>
<br>
<text>月相:{{item.moonPhase}}&月出:{{item.sunrise}}&月落:{{item.moonset}}
<br>

<text>月相:{{item.moonPhase}} 月出:{{item.sunrise}} 月落:{{item.moonset}}
<br>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,4 @@
"engines": {
"node": ">=14"
}
}
}
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14587,4 +14587,4 @@ zepto@^1.2.0:
zwitch@^1.0.0:
version "1.0.5"
resolved "https://registry.yarnpkg.com/zwitch/-/zwitch-1.0.5.tgz#d11d7381ffed16b742f6af7b3f223d5cd9fe9920"
integrity sha512-V50KMwwzqJV0NpZIZFwfOD5/lyny3WlSzRiXgA0G7VUnRlqttta1L6UQIHzd6EuBY/cHGfwTIck7w1yH6Q5zUw==
integrity sha512-V50KMwwzqJV0NpZIZFwfOD5/lyny3WlSzRiXgA0G7VUnRlqttta1L6UQIHzd6EuBY/cHGfwTIck7w1yH6Q5zUw==

0 comments on commit c0f74d1

Please sign in to comment.