介绍
# Weather CLI
使用 `weathercli` 命令获取全球任何地点的天气信息。
## 命令
### 当前天气
获取实时天气状况,包括温度、湿度、风力和降水。
```bash weathercli current "<location>" weathercli current "<location>" --json ```
**返回:** 当前温度、“体感”温度、湿度%、风速/风向、气压、云量、紫外线指数、降水量、天气状况描述以及本地时区的时间戳。
### 预报
获取每日或每小时天气预报。
```bash # Daily forecast (default: 7 days, max: 16) weathercli forecast "<location>" --days <N>
# Hourly forecast (max: 384 hours) weathercli forecast "<location>" --hourly --hours <N>
# JSON output for parsing weathercli forecast "<location>" --json ```
**返回:** 对于每一天/小时:温度(最高/最低或当前)、天气状况、降水概率和降水量、风速/风向、紫外线指数、日出/日落时间(仅每日)。
### 位置搜索
查找某个地点的坐标和时区信息。
```bash weathercli search "<location>" weathercli search "<location>" --json ```
**返回:** 地点名称、坐标(纬度/经度)、国家、地区/州、时区。
## 位置格式
位置格式灵活,会自动进行地理编码: - 城市名称:`"London"`、`"Tokyo"`、`"New York"` - 城市 + 国家:`"Paris, France"`、`"Berlin, Germany"` - 城市 + 州/地区:`"Portland, Oregon"`、`"Barcelona, Catalonia"` - 有歧义的名称:添加国家/地区以确保精确性
## 选项
- `--json` - 输出结构化的 JSON(推荐用于解析) - `--no-color` - 禁用颜色输出(用于纯文本解析) - `--days N` - 预报的天数(1-16,默认:7) - `--hourly` - 显示每小时预报而非每日预报 - `--hours N` - 每小时预报的小时数(1-384) - `--verbose` - 显示详细的请求信息
## 输出格式
### 人类可读(默认)
颜色编码的温度,带有表情符号和单位格式。时间显示为地点的本地时区。
### JSON 结构
**当前天气:** ```json { "location": { "name": "Tokyo", "latitude": 35.6895, "longitude": 139.6917, "country": "Japan", "timezone": "Asia/Tokyo" }, "time": "2026-01-12T18:45:00+09:00", "temperature": 4.7, "apparent": 1.8, "humidity": 66, "wind_speed": 3.6, "wind_direction": 135, "condition": "Clear sky", "weather_code": 0, "precipitation": 0, "cloud_cover": 0, "pressure": 1015.2, "uv_index": 0 } ```
**预报:** ```json { "location": { ... }, "daily": [ { "date": "2026-01-12", "temp_max": 12.1, "temp_min": 4.3, "condition": "Slight rain", "precip_prob": 75, "precipitation": 1.5, "sunrise": "2026-01-12T08:04:00+09:00", "sunset": "2026-01-12T16:45:00+09:00", "wind_speed_max": 15.3, "wind_direction": 202, "uv_index_max": 2.4 } ] } ```
## 使用指南
### 何时使用
- 用户询问天气、温度、预报或天气状况 - 规划活动并需要天气数据 - 检查是否会下雨、下雪或天晴 - 获取旅行规划所需的气候信息 - 需要日出/日落时间 - 比较不同地点的天气
### 位置处理
1. 如果用户提供了明确的位置,直接使用 2. 如果有歧义(例如“Portland”),请求澄清或添加上下文 3. 如果找不到位置,建议检查拼写或添加国家 4. 对于坐标,先使用 `search` 命令进行验证
### 解析输出
- **程序解析时务必使用 `--json`** - 提取 `temperature`、`condition`、`wind_speed` 以快速获取摘要 - 检查 `precip_prob` 以了解降雨可能性 - 使用 `sunrise`/`sunset` 进行白昼规划 - `weather_code` 遵循 WMO 标准(0-99)
### 最佳实践
- 旅行规划请求 3-5 天(而非全部 16 天) - 使用每小时预报进行详细的日程规划 - 检查 `apparent`(体感)温度以了解舒适度 - 紫外线指数 >3 = 建议防晒 - 风速 >20 km/h = 提及风大
## 示例
**快速查看天气:** ```bash weathercli current "London" --json | jq '.temperature, .condition' ```
**旅行的一周预报:** ```bash weathercli forecast "Barcelona" --days 5 --json ```
**今天的详细每小时预报:** ```bash weathercli forecast "Seattle" --hourly --hours 24 ```
**查询多个城市:** ```bash for city in "Tokyo" "London" "New York"; do weathercli current "$city" --json | jq -r '"\(.location.name): \(.temperature)°C, \(.condition)"' done ```
**查找确切位置:** ```bash weathercli search "Springfield" --json ```
## 注意事项
- **无需 API 密钥** - 使用免费的 Open-Meteo API - **全球覆盖** - 适用于全球任何位置 - **温度单位为摄氏度** - 如需转换(°F = °C × 9/5 + 32) - **风速单位为 km/h** - 如需转换为 mph(×0.621) - **本地时区** - 所有时间自动转换 - **速率限制** - 适用于个人/代理使用;避免频繁请求 - **准确性** - 数据来自多个气象来源 - **更新频率** - 当前天气每 15 分钟更新一次 - **离线** - 需要互联网连接
## 错误处理
**位置未找到:** ``` Error: location not found: Atlantis ``` → 检查拼写,尝试添加国家/地区
**网络错误:** ``` Error: weather API error: network timeout ``` → 短暂延迟后重试
**无效输入:** ``` Error: invalid days value ``` → 检查 `--days` 是否在 1-16 之间
## 安装
如果 `weathercli` 不可用: ```bash # Via Go go install github.com/pjtf93/weathercli/cmd/weathercli@latest
# Or download binary from releases # https://github.com/pjtf93/weathercli/releases ```