本工具集成两个高质量的免费天气数据源,无需申请任何 API Key 即可通过命令行快速调用。
wttr.in 是最适合在终端直接阅读的服务。
```bash
curl -s "wttr.in/Shanghai?format=3"
# 预期输出:Shanghai: ☀️ +22°C
```
```bash
curl -s "wttr.in/Beijing?format=%l:+%c+%t+%h+%w"
# 输出示例:Beijing: ⛅️ +15°C 60% ↗10km/h
```
```bash
curl -s "wttr.in/Guangzhou?T"
```
使用格式符自定义输出:
| 占位符 | 含义 | 占位符 | 含义 |
| :--- | :--- | :--- | :--- |
| %l | 地名 | %h | 湿度 |
| %c | 天气图标 | %w | 风力/风向 |
| %t | 摄氏度 | %m | 月相 |
+ 连接(如 wttr.in/New+York)。
wttr.in/PVG)。
?m,如需美制单位可加 ?u。
?0 仅查看当前,?1 仅看今日。
wttr.in/Paris.png -o weather.png)。
如果你需要编写脚本或处理结构化数据,Open-Meteo 提供的 JSON 响应是更佳的选择。
该服务基于经纬度提供高度精准的天气编码、风速及气温数据。
# 以伦敦坐标 (51.5, -0.12) 为例
curl -s "[https://api.open-meteo.com/v1/forecast?latitude=51.5&longitude=-0.12¤t_weather=true](https://api.open-meteo.com/v1/forecast?latitude=51.5&longitude=-0.12¤t_weather=true)"
共 1 个版本