From c0f74d1b884b672f9cdc4e24006bbb99cec1a339 Mon Sep 17 00:00:00 2001
From: Rein-Ou <52846432+Rein-Ou@users.noreply.github.com>
Date: Sat, 26 Mar 2022 17:55:04 +0800
Subject: [PATCH] fix(route): Weather forcast (#9390)
* 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
---
docs/forecast.md | 20 ++++++++++----------
lib/v2/weather/index.js | 19 ++++++++++++++-----
lib/v2/weather/util/weather.art | 17 ++++++++---------
package.json | 2 +-
yarn.lock | 2 +-
5 files changed, 34 insertions(+), 26 deletions(-)
diff --git a/docs/forecast.md b/docs/forecast.md
index 1247f126d0af83..9d1c2b5b32390d 100644
--- a/docs/forecast.md
+++ b/docs/forecast.md
@@ -58,16 +58,6 @@ pageClass: routes
-## 和风天气
-
-### 近三天天气
-
-
-
-需自行注册获取和风天气 api 的 key,并在环境变量 HEFENG_KEY 中进行配置,获取订阅近三天天气预报
-
-
-
## 上海市生态环境局
### 空气质量
@@ -139,3 +129,13 @@ pageClass: routes
可通过全局过滤参数订阅您感兴趣的地区.
+
+## 和风天气
+
+### 近三天天气
+
+
+
+需自行注册获取 api 的 key,并在环境变量 HEFENG_KEY 中进行配置,获取订阅近三天天气预报
+
+
diff --git a/lib/v2/weather/index.js b/lib/v2/weather/index.js
index 5fab477a7b02f6..55bcb435697167 100644
--- a/lib/v2/weather/index.js
+++ b/lib/v2/weather/index.js
@@ -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]);
@@ -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,
};
};
diff --git a/lib/v2/weather/util/weather.art b/lib/v2/weather/util/weather.art
index c282d3a4958823..5d97c1d928a388 100644
--- a/lib/v2/weather/util/weather.art
+++ b/lib/v2/weather/util/weather.art
@@ -2,20 +2,19 @@
气温:{{item.tempMin}}℃~{{item.tempMax}}℃
-相对湿度:{{item.humidity}}(%)
+相对湿度:{{item.humidity}}%
-大气压强:{{item.pressure}}(百帕)
+大气压强:{{item.pressure}}百帕
紫外线强度:{{item.uvIndex}}
-白天风向:{{item.windDirDay}};风力:{{item.windScaleDay}}级;风速:{{item.windSpeedDay}}公里/小时
+白天风向:{{item.windDirDay}} 风力:{{item.windScaleDay}}级 风速:{{item.windSpeedDay}}公里/小时
-夜间风向:{{item.windDirNight}};风力:{{item.windScaleNight}}级;风速:{{item.windSpeedNight}}公里/小时
+夜间风向:{{item.windDirNight}} 风力:{{item.windScaleNight}}级 风速:{{item.windSpeedNight}}公里/小时
-能见度:{{item.vis}}(公里)
+能见度:{{item.vis}}公里
-日出:{{item.sunrise}}&日落: {{item.sunset}}
+日出:{{item.sunrise}} 日落: {{item.sunset}}
-月相:{{item.moonPhase}}&月出:{{item.sunrise}}&月落:{{item.moonset}}
-
-
+月相:{{item.moonPhase}} 月出:{{item.sunrise}} 月落:{{item.moonset}}
+
\ No newline at end of file
diff --git a/package.json b/package.json
index 8c7c52060a363c..777ffb72534417 100644
--- a/package.json
+++ b/package.json
@@ -162,4 +162,4 @@
"engines": {
"node": ">=14"
}
-}
+}
\ No newline at end of file
diff --git a/yarn.lock b/yarn.lock
index 03d15abad713c3..89679f36ebfa13 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -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==
\ No newline at end of file