Install
openclaw skills install @thcjp/free-weather-skill-tool-freeopenclaw skills install @thcjp/free-weather-skill-tool-free本工具为个人用户与开发者提供完全免费的天气查询能力,基于 wttr.in 与 Open-Meteo 两大免费服务,无需任何 API Key 即可查询全球城市天气。支持文本、JSON、PNG 多种输出格式,既适合命令行日常查询,也适合脚本化编程集成。
免费版聚焦命令行查询与开发调试场景,零配置开箱即用。
| 能力模块 | 描述 | 免费版支持 |
|---|---|---|
| 城市天气查询 | 全球主要城市天气 | 支持 |
| 实时天气 | 当前温度、湿度、风力 | 支持 |
| 多日预报 | 未来 3 天预报 | 支持 |
| 文本输出 | 一行式摘要 | 支持 |
| 全景输出 | 终端可视化预报 | 支持 |
| JSON 输出 | 编程友好格式 | 支持 |
| PNG 图像 | 天气图导出 | 支持 |
| 月相信息 | 月亮状态 | 支持 |
| API Key | 是否需要 | 无需 |
| 历史数据 | 过去天气 | 不支持 (升级 PRO) |
| 多城市批量 | 同时查询多个 | 不支持 (升级 PRO) |
| 定时推送 | 自动推送 | 不支持 (升级 PRO) |
用input_params参数进行配置。
输入: 用户提供核心功能执行所需的指令和必要参数。 处理: 解析核心功能执行的输入参数,完成核心逻辑,返回结构化响应。 输出: 返回核心功能执行的响应数据,包含状态码、结果和日志。
input_params参数,支持创建/查询/导出操作用config_options参数进行配置。
输入: 用户提供参数配置与调用所需的指令和必要参数。 处理: 解析参数配置与调用的输入参数,完成核心逻辑,返回结构化响应。 输出: 返回参数配置与调用的响应数据,包含状态码、结果和日志。
config_options参数,支持修改/重置/导入操作用output_format参数进行配置。
输入: 用户提供结果处理与输出所需的指令和必要参数。 处理: 解析结果处理与输出的输入参数,完成核心逻辑,返回结构化响应。 输出: 返回结果处理与输出的响应数据,包含状态码、结果和日志。
output_format参数,支持导出/保存/转换操作
能力覆盖范围:本skill的核心能力覆盖以下场景关键词:wttr、Open、Meteo、查询全球天气、面向个人用户的轻、量天气查询工具、完全免费且无需、核心能力、全球城市天气查询、多格式输出、编程接口、命令行便捷调用、适用场景、个人出行查询、脚本集成、开发调试、终端天气展示、差异化、免费版聚焦命令行、零配置开箱即用、适合个人与开发者、适用关键词、免费天气、命令行天气等。这些关键词对应description中声明的使用场景,均已在上述能力点中提供对应的操作支持。# 一行式摘要
curl -s "wttr.in/Beijing?format=3"
# 输出: Beijing: ☁️ +15°C
# ...
# 自定义格式
curl -s "wttr.in/Beijing?format=%l:+%c+%t+%h+%w"
# 输出: Beijing: ☁️ +15°C 45% ↓12km/h
# ...
# 完整终端预报
curl -s "wttr.in/Beijing?T"
# 输出彩色 ASCII 天气图
import requests
# ...
def get_weather(city):
"""获取天气 JSON 数据"""
url = f"https://wttr.in/{city}"
params = {"format": "j1"}
resp = requests.get(url, params=params, timeout=30)
return resp.json()
# ...
def get_open_meteo(lat, lon):
"""Open-Meteo 备选方案"""
url = "https://api.open-meteo.com/v1/forecast"
params = {
"latitude": lat,
"longitude": lon,
"current_weather": True,
"timezone": "auto",
}
resp = requests.get(url, params=params, timeout=30)
return resp.json()
# ...
# 北京: lat=39.9, lon=116.4
weather = get_open_meteo(39.9, 116.4)
print(f"温度: {weather['current_weather']['temperature']}°C")
print(f"风速: {weather['current_weather']['windspeed']} km/h")
# 终端显示彩色 ASCII 天气图
curl -s "wttr.in/Shanghai?T&lang=zh"
# ...
# 仅查询今天
curl -s "wttr.in/Shanghai?1&lang=zh"
# ...
# 仅查询当前
curl -s "wttr.in/Shanghai?0&lang=zh"
# ...
# 导出 PNG 图片
curl -s "wttr.in/Berlin.png" -o /tmp/weather.png
以下场景免费天气技能免费版不适合处理:
需要代码生成、编程辅助、调试测试、开发部署时使用。不适用于非本工具能力范围的需求。
# 依赖说明
curl -s "wttr.in/your_city"
# 在 ~/.bashrc 或 ~/.zshrc 中添加
alias weather='curl -s "wttr.in/$1?lang=zh"'
alias weather-json='curl -s "wttr.in/$1?format=j1"'
# ...
# 使用
weather 北京
weather-json 上海
# 当 wttr.in 不可用时,使用 Open-Meteo
curl -s "https://api.open-meteo.com/v1/forecast?latitude=39.9&longitude=116.4¤t_weather=true"
响应解析: 完成完成后,查看输出响应确认任务状态。成功时输出包含解析摘要和响应数据;失败时根据错误信息排查问题,查阅错误解析章节获取恢复步骤。
| 代码 | 含义 | 示例 |
|---|---|---|
%c | 天气状况图标 | ☁️ |
%t | 温度 | +15°C |
%h | 湿度 | 45% |
%w | 风速 | ↓12km/h |
%l | 地点 | Beijing |
%m | 月相 | 🌕 |
%p | 降水量 | 0.0mm |
%P | 气压 | 1013hPa |
# 多字段组合
curl -s "wttr.in/Beijing?format=%l:+%c+%t+%h+%w+%p"
# ...
# 自定义分隔符
curl -s "wttr.in/Beijing?format=%l|%c|%t|%h|%w"
# ...
# JSON 格式 (编程用)
curl -s "wttr.in/Beijing?format=j1"
# ...
# 简短中文
curl -s "wttr.in/Beijing?format=3&lang=zh"
import requests
from dataclasses import dataclass
from typing import Optional
# ...
@dataclass
class WeatherData:
location: str
temperature: str
condition: str
humidity: str
wind: str
moon_phase: Optional[str] = None
# ...
class WeatherTool:
def __init__(self):
self.base_url = "https://wttr.in"
self.fallback_url = "https://api.open-meteo.com/v1/forecast"
# ...
def quick(self, city):
"""一行式查询"""
resp = requests.get(
f"{self.base_url}/{city}",
params={"format": "3", "lang": "zh"},
timeout=30,
)
return resp.text.strip()
# ...
def detailed(self, city):
"""详细查询"""
resp = requests.get(
f"{self.base_url}/{city}",
params={"format": "j1"},
timeout=30,
)
data = resp.json()
current = data["current_condition"][0]
return WeatherData(
location=data["nearest_area"][0]["areaName"][0]["value"],
temperature=current["temp_C"] + "°C",
condition=current["weatherDesc"][0]["value"],
humidity=current["humidity"] + "%",
wind=f"{current['winddir16Point']} {current['windspeedKmph']}km/h",
moon_phase=data.get("weather", [{}])[0].get("astronomy", [{}])[0].get("moon_phase"),
)
# ...
def fallback(self, lat, lon):
"""Open-Meteo 备选"""
resp = requests.get(
self.fallback_url,
params={"latitude": lat, "longitude": lon, "current_weather": True},
timeout=30,
)
return resp.json()
#!/bin/bash
# ~/.local/(请参考skill目录中的脚本文件)
# ...
CITY="${1:-Beijing}"
FORMAT="${2:-default}"
# ...
case "$FORMAT" in
"short")
curl -s "wttr.in/$CITY?format=3&lang=zh"
;;
"json")
curl -s "wttr.in/$CITY?format=j1"
;;
"png")
curl -s "wttr.in/$CITY.png" -o "/tmp/weather_$CITY.png"
echo "图片已保存到 /tmp/weather_$CITY.png"
;;
"full"|"default")
curl -s "wttr.in/$CITY?T&lang=zh"
;;
*)
echo "用法: weather <city> [short|json|png|full]"
echo "默认: weather Beijing"
;;
esac
# URL 编码空格
curl -s "wttr.in/New+York"
curl -s "wttr.in/San+Francisco"
# ...
# 使用拼音
curl -s "wttr.in/Shanghai"
# ...
# 使用机场代码
curl -s "wttr.in/PEK" # 北京首都机场
curl -s "wttr.in/PVG" # 上海浦东机场
# 公制 (默认,中国适用)
curl -s "wttr.in/Beijing?m"
# ...
# 美制
curl -s "wttr.in/New+York?u"
# 仅今天
curl -s "wttr.in/Beijing?1"
# ...
# 仅当前
curl -s "wttr.in/Beijing?0"
# ...
# 去除 ANSI 颜色 (适合管道)
curl -s "wttr.in/Beijing?T" | sed 's/\x1b\[[0-9;]*m//g'
def robust_weather(city):
"""主备方案自动切换"""
try:
return requests.get(
f"https://wttr.in/{city}",
params={"format": "j1"},
timeout=10,
).json()
except Exception:
# 切换到 Open-Meteo
coords = get_coordinates(city)
return requests.get(
"https://api.open-meteo.com/v1/forecast",
params={"latitude": coords[0], "longitude": coords[1], "current_weather": True},
timeout=30,
).json()
是的,wttr.in 与 Open-Meteo 均为免费公共服务,无需注册与 API Key。
wttr.in 建议不超过每分钟 10 次以避免被限流。Open-Meteo 限制为每天 10000 次。
支持。添加 &lang=zh 参数即可获得中文天气描述。
确保终端使用 UTF-8 编码。Linux/macOS 默认支持,Windows 用户需要 chcp 65001 切换。
切换到 Open-Meteo 备选方案,或等待一段时间重试。如需 SLA 保障,可升级 PRO 版本。
| 依赖项 | 类型 | 是否必需 | 获取方式 |
|---|---|---|---|
| wttr.in | 在线 API | 主选 | 免费,无需 Key |
| Open-Meteo | 在线 API | 备选 | 免费,无需 Key |
| LLM API | 推理服务 | 必需 | 由 Agent 内置 LLM 提供 |
| curl | 命令行工具 | 推荐 | 系统自带 |
| Python 3.8+ | 运行时 | 可选 | python.org 下载 |
# 免费版完全无需 API Key
# 直接使用即可
# ...
# 可选: 默认城市
export WEATHER_DEFAULT_CITY="Beijing"
export WEATHER_LANG="zh"
| 错误场景 | 原因 | 处理方式 |
|---|---|---|
| 配置错误 | 参数缺失或格式错误 | 检查依赖说明中的配置要求 |
| 运行时错误 | 运行环境不满足 | 确认运行环境符合依赖说明 |
| 网络错误 | 连接超时或不可达 | 执行ping命令测试网络连通性,检查防火墙和代理设置连接后执行ping命令测试网络连通性,检查防火墙和代理设置连接后重新执行命令,参考国内替代方案 |
{
"success": true,
"data": {
"result": "免费天气技能免费版处理结果",
"execution_time": "0.5s",
"metadata": {
"version": "1.0",
"processor": "free weather skill"
}
},
"execution_log": ["解析输入参数", "执行核心处理", "格式化输出结果"],
"error": null
}