Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(route): Weather forcast #9390

Merged
merged 20 commits into from
Mar 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>

## 和风天气
Copy link
Collaborator

@TonyRL TonyRL Mar 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub Actions will sort in pinyin order. No need to put it to the bottom.


### 近三天天气

<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==