Weather Search Skill
Query real-time weather information using Amap (高德地图) Weather API.
API Documentation
https://lbs.amap.com/api/javascript-api/guide/services/weather
Prerequisites
- 1. Get Amap API Key
- Visit: https://console.amap.com/
- Create an application
- Get your Web Service (Key)
- 2. Set Environment Variable
CODEBLOCK0
Usage
Query Weather by City Name
CODEBLOCK1
Query Weather by City Code
CODEBLOCK2
Query Multiple Cities
CODEBLOCK3
Query by Coordinates (Latitude, Longitude)
CODEBLOCK4
API Parameters
| Parameter | Type | Required | Description |
|---|
| city | String | Yes (or location) | City name or city code |
| location |
String | Yes (or city) | Format: longitude,latitude |
| key | String | Yes | Amap API Key |
| output | String | No | Response format: json or xml (default: json) |
Response Example
CODEBLOCK5
Quick Start Script
Create a weather query script:
CODEBLOCK6
Make it executable:
CODEBLOCK7
City Code Reference
| City | Code |
|---|
| Beijing | 110000 |
| Shanghai |
310000 |
| Guangzhou | 440100 |
| Shenzhen | 440300 |
| Hangzhou | 330100 |
| Chengdu | 510100 |
| Wuhan | 420100 |
| Xi'an | 610100 |
Notes
- - API Key is required for all requests
- Free tier: 1000 requests/day
- Response includes: weather condition, temperature, wind direction, wind power, humidity
- Supports both Chinese city names and city codes
天气查询技能
使用高德地图天气API查询实时天气信息。
API文档
https://lbs.amap.com/api/javascript-api/guide/services/weather
前置条件
- 1. 获取高德地图API密钥
- 访问:https://console.amap.com/
- 创建应用
- 获取Web服务密钥
- 2. 设置环境变量
bash
export AMAP
APIKEY=your
apikey_here
使用方法
按城市名称查询天气
bash
curl -X GET https://restapi.amap.com/v3/weather/weatherInfo?city=BEIJING&key=YOUR
APIKEY&output=json
按城市编码查询天气
bash
curl -X GET https://restapi.amap.com/v3/weather/weatherInfo?city=110000&key=YOUR
APIKEY&output=json
查询多个城市
bash
curl -X GET https://restapi.amap.com/v3/weather/weatherInfo?city=BEIJING|SHANGHAI|GUANGZHOU&key=YOUR
APIKEY&output=json
按坐标查询(纬度,经度)
bash
curl -X GET https://restapi.amap.com/v3/weather/weatherInfo?location=116.40,39.90&key=YOUR
APIKEY&output=json
API参数
| 参数 | 类型 | 必填 | 描述 |
|---|
| city | 字符串 | 是(或location) | 城市名称或城市编码 |
| location |
字符串 | 是(或city) | 格式:经度,纬度 |
| key | 字符串 | 是 | 高德地图API密钥 |
| output | 字符串 | 否 | 响应格式:json或xml(默认:json) |
响应示例
json
{
status: 1,
infocode: 10000,
info: 查询成功,
count: 1,
lives: [
{
province: 北京,
city: 北京,
adcode: 110000,
weather: 晴,
temperature: 25,
winddirection: 北,
windpower: 2,
humidity: 45,
reporttime: 2024-01-15 12:00:00
}
]
}
快速启动脚本
创建天气查询脚本:
bash
#!/bin/bash
weather.sh
APIKEY=${AMAPAPIKEY:-yourapikeyhere}
CITY=$1
if [ -z $CITY ]; then
echo 用法:weather.sh <城市名称或编码>
exit 1
fi
curl -s https://restapi.amap.com/v3/weather/weatherInfo?city=${CITY}&key=${API_KEY}&output=json | jq .
赋予执行权限:
bash
chmod +x weather.sh
./weather.sh BEIJING
城市编码参考
310000 |
| 广州 | 440100 |
| 深圳 | 440300 |
| 杭州 | 330100 |
| 成都 | 510100 |
| 武汉 | 420100 |
| 西安 | 610100 |
注意事项
- - 所有请求都需要API密钥
- 免费额度:每天1000次请求
- 响应包含:天气状况、温度、风向、风力、湿度
- 支持中文城市名称和城市编码