feat(route): add Weather forcast (#9382)
* weather_forcast * format * cache * Update lib/v2/weather/index.js Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update lib/v2/weather/util/location.js Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update docs/forecast.md Co-authored-by: Tony <TonyRL@users.noreply.github.com> * modify * Update forecast.md * readme.md * docs: reorder `HEFENG_KEY`
This commit is contained in:
parent
8ecad32db2
commit
2a728f1e1c
|
|
@ -129,3 +129,13 @@ pageClass: routes
|
|||
可通过全局过滤参数订阅您感兴趣的地区.
|
||||
|
||||
</Route>
|
||||
|
||||
## 和风天气
|
||||
|
||||
### 近三天天气
|
||||
|
||||
<Route author="Rein-Ou" example="/weather/广州" path="/weather/:location" selfhost="1">
|
||||
|
||||
需自行注册获取和风天气 api 的 key,并在环境变量HEFENG_KEY中进行配置,获取订阅近三天天气预报
|
||||
|
||||
</Route>
|
||||
|
|
|
|||
|
|
@ -700,6 +700,10 @@ RSSHub 支持使用访问密钥 / 码,白名单和黑名单三种方式进行
|
|||
- `FANFOU_USERNAME`: 饭否登录用户名、邮箱、手机号
|
||||
- `FANFOU_PASSWORD`: 饭否密码
|
||||
|
||||
- 和风天气:[申请地址](https://id.qweather.com/#/register?redirect=https%3A%2F%2Fconsole.qweather.com)
|
||||
|
||||
- `HEFENG_KEY`:API key
|
||||
|
||||
- 南方周末付费全文
|
||||
|
||||
- `INFZM_COOKIE`: infzm 账户登陆后的 cookie,目前只需要 `passport_session=...` 即可获取全文
|
||||
|
|
|
|||
|
|
@ -149,6 +149,10 @@ const calculateValue = () => {
|
|||
google: {
|
||||
fontsApiKey: envs.GOOGLE_FONTS_API_KEY,
|
||||
},
|
||||
hefeng: {
|
||||
// weather
|
||||
key: envs.HEFENG_KEY,
|
||||
},
|
||||
infzm: {
|
||||
cookie: envs.INFZM_COOKIE,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/weather/:location': ['Rein-Ou'],
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/:location', require('./index'));
|
||||
};
|
||||
|
|
@ -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>
|
||||
|
||||
|
|
@ -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==
|
||||
Loading…
Reference in New Issue