名称: weathercli
描述: 获取全球任意地点的实时天气状况与天气预报。返回包含温度、湿度、风速、降水等信息的结构化数据。无需 API 密钥。
使用 weathercli 命令获取全球任意地点的天气信息。
获取实时天气状况,包括温度、湿度、风速和降水。
weathercli current "<地点>"
weathercli current "<地点>" --json
返回信息: 当前温度、体感温度、湿度百分比、风速/风向、气压、云量、紫外线指数、降水量、天气状况描述以及当地时区的时间戳。
获取每日或每小时的天气预报。
# 每日预报(默认:7天,最多:16天)
weathercli forecast "<地点>" --days <天数>
# 每小时预报(最多:384小时)
weathercli forecast "<地点>" --hourly --hours <小时数>
# JSON 输出,便于解析
weathercli forecast "<地点>" --json
返回信息: 针对每一天/小时:温度(最高/最低或当前值)、天气状况、降水概率与降水量、风速/风向、紫外线指数、日出/日落时间(仅每日预报)。
查找地点的坐标和时区信息。
weathercli search "<地点>"
weathercli search "<地点>" --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 - 显示详细的请求信息温度以颜色区分,格式包含表情符号和单位。时间显示为当地时区时间。
当前天气:
{
"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
}
天气预报:
{
"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
}
]
}
search 命令进行验证--json 进行程序化解析temperature、condition、wind_speed 以快速总结precip_prob 了解降雨可能性sunrise/sunset 进行日光规划weather_code 遵循 WMO 标准(0-99)apparent 温度了解体感舒适度快速天气查询:
weathercli current "London" --json | jq '.temperature, .condition'
旅行周预报:
weathercli forecast "Barcelona" --days 5 --json
今日详细小时预报:
weathercli forecast "Seattle" --hourly --hours 24
检查多个城市:
for city in "Tokyo" "London" "New York"; do
weathercli current "$city" --json | jq -r '"\(.location.name): \(.temperature)°C, \(.condition)"'
done
查找精确地点:
weathercli search "Springfield" --json
未找到地点:
Error: location not found: Atlantis
→ 检查拼写,尝试添加国家/地区信息
网络错误:
Error: weather API error: network timeout
→ 短暂延迟后重试
输入无效:
Error: invalid days value
→ 检查 --days 值是否在 1-16 之间
如果 weathercli 不可用:
# 通过 Go 安装
go install github.com/pjtf93/weathercli/cmd/weathercli@latest
# 或从发布页面下载二进制文件
# https://github.com/pjtf93/weathercli/releases