免费天气技能免费版

通过 wttr.in 和 Open-Meteo 免费 API,零配置命令行查询全球天气,支持文本、JSON 和 PNG 格式,无需 API Key。

天轰穿

@thcjp

What This Skill Does

Command-line weather tool that queries global weather via wttr.in and Open-Meteo free APIs. Supports text, JSON, and PNG output formats with zero configuration and no API key required.

Eliminates the need for API keys and complex setup by providing instant weather data through simple curl commands or script integration.

When to Use It

  • Check current weather for a city from the terminal
  • Get a 3-day forecast in a readable ASCII format
  • Fetch weather data as JSON for use in scripts or applications
  • Export a weather report as a PNG image
  • Set up a shell alias for quick weather lookups
  • Use Open-Meteo as a fallback when wttr.in is unavailable

Install

$ openclaw 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

不适用场景

以下场景免费天气技能免费版不适合处理:

  • 无明确技术栈的模糊需求
  • 纯架构设计决策
  • 运维部署管理

触发条件

需要代码生成、编程辅助、调试测试、开发部署时使用。不适用于非本工具能力范围的需求.

快速开始

Step 1: 直接使用

# 依赖说明
curl -s "wttr.in/your_city"

Step 2: 设置别名 (可选)

# 在 ~/.bashrc 或 ~/.zshrc 中添加
alias weather='curl -s "wttr.in/$1?lang=zh"'
alias weather-json='curl -s "wttr.in/$1?format=j1"'
# ...
# 使用
weather 北京
weather-json 上海

Step 3: 使用 Open-Meteo 备选

# 当 wttr.in 不可用时,使用 Open-Meteo
curl -s "https://api.open-meteo.com/v1/forecast?latitude=39.9&longitude=116.4&current_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"

Python 封装工具

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):
        """详细查询"""
            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 备选"""
            self.fallback_url,
            params={"latitude": lat, "longitude": lon, "current_weather": True},
            timeout=30,
        )
        return resp.json()

Shell 脚本封装

#!/bin/bash
# ~/.local/(请参考skill目录中的脚本文件)
# ...
CITY="${1:-Beijing}"
FORMAT="${2:-default}"
# ...
case "$FORMAT" in
    "short")
        curl -s "wttr.in/$CITY?format=3&lang=zh"
        ;;
    "json")
        ;;
    "png")
in/$CITY.png" -o "/tmp/weather_$CITY.png"
        echo "图片已保存到 /tmp/weather_$CITY.png"
        ;;
    "full"|"default")
        ;;
    *)
        echo "用法: weather <city> [short|json|png|full]"
        echo "默认: weather Beijing"
        ;;
esac

最佳实践

1. 城市名称处理

# 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"  # 上海浦东机场

2. 单位选择

# 公制 (默认,中国适用)
curl -s "wttr.in/Beijing?m"
# ...
# 美制
curl -s "wttr.in/New+York?u"

3. 简化输出

# 仅今天
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'

4. 故障转移

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)
            "https://api.open-meteo.com/v1/forecast",
            params={"latitude": coords[0], "longitude": coords[1], "current_weather": True},
            timeout=30,
        ).json()

常见问题

Q1: 真的完全免费吗?

是的,wttr.in 与 Open-Meteo 均为免费公共服务,无需注册与 API Key.

已知限制

wttr.in 建议不超过每分钟 10 次以避免被限流。Open-Meteo 限制为每天 10000 次.

Q3: 支持中文输出吗?

支持。添加 &lang=zh 参数即可获得中文天气描述.

Q4: 终端中文乱码怎么办?

确保终端使用 UTF-8 编码。Linux/macOS 默认支持,Windows 用户需要 chcp 65001 切换.

Q5: 服务不可用怎么办?

切换到 Open-Meteo 备选方案,或等待一段时间重试。如需 SLA 保障,可升级 PRO 版本.

依赖说明

运行环境

  • Agent 平台: 支持 SKILL.md 规范的任意 AI Agent (Claude Code、Cursor、Codex、Gemini CLI 等)
  • 操作系统: Windows / macOS / Linux
  • 网络: 需访问 wttr.in 或 Open-Meteo

第三方依赖

依赖项类型是否必需获取方式
wttr.in在线 API主选免费,无需 Key
Open-Meteo在线 API备选免费,无需 Key
LLM API推理服务必需由 Agent 内置 LLM 提供
curl命令行工具推荐系统自带
Python 3.8+运行时可选python.org 下载

API Key 配置

# 免费版完全无需 API Key
# 直接使用即可
# ...
# 可选: 默认城市
export WEATHER_DEFAULT_CITY="Beijing"
export WEATHER_LANG="zh"

可用性分类

  • 分类: MD+EXEC (Markdown 指令 + 命令行执行)
  • 说明: 本 Skill 通过自然语言指令驱动 Agent 调用免费天气 API,完全零配置
  • 免费版特性: 无需 API Key、命令行优先、多格式输出、双服务冗余
  • 限制: 单城市查询、3 天预报、无 SLA、可能被限流

错误处理

错误场景原因处理方式
配置错误参数缺失或格式错误检查依赖说明中的配置要求
运行时错误运行环境不满足确认运行环境符合依赖说明
网络错误连接超时或不可达执行ping命令测试网络连通性,检查防火墙和代理设置连接后执行ping命令测试网络连通性,检查防火墙和代理设置连接后重新执行命令,参考国内替代方案

输出格式

{
  "success": true,
  "data": {
    "result": "免费天气技能免费版处理结果",
    "execution_time": "0.5s",
    "metadata": {
      "version": "1.0",
      "processor": "free weather skill"
    }
  },
  "execution_log": ["解析输入参数", "执行核心处理", "格式化输出结果"],
  "error": null
}

Top skills in this category