weather-query

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Weather Query Skill

天气查询Skill

This skill enables AI agents to fetch real-time weather information and forecasts for locations in China using the 60s API.
该Skill可让AI Agent通过60s API获取中国各地的实时天气信息和天气预报。

When to Use This Skill

何时使用该Skill

Use this skill when users:
  • Ask about current weather conditions
  • Want weather forecasts
  • Need temperature, humidity, wind information
  • Request air quality data
  • Plan outdoor activities and need weather info
当用户有以下需求时使用本Skill:
  • 询问当前天气状况
  • 需要查看天气预报
  • 想了解温度、湿度、风力信息
  • 请求空气质量数据
  • 规划户外活动,需要天气参考信息

API Endpoints

API接口

1. Real-time Weather

1. 实时天气

URL:
https://60s.viki.moe/v2/weather/realtime

Method: GET
URL:
https://60s.viki.moe/v2/weather/realtime

请求方式: GET

2. Weather Forecast

2. 天气预报

URL:
https://60s.viki.moe/v2/weather/forecast

Method: GET
URL:
https://60s.viki.moe/v2/weather/forecast

请求方式: GET

Parameters

参数说明

  • location
    (required): Location name in Chinese
    • Can be city name: "北京", "上海", "广州"
    • Can be district name: "海淀区", "浦东新区"
  • location
    (必填):中文地点名称
    • 可以是城市名:"北京", "上海", "广州"
    • 可以是区/县名:"海淀区", "浦东新区"

How to Use

使用方法

Get Real-time Weather

获取实时天气

python
import requests

def get_realtime_weather(location):
    url = 'https://60s.viki.moe/v2/weather/realtime'
    response = requests.get(url, params={'location': location})
    return response.json()
python
import requests

def get_realtime_weather(location):
    url = 'https://60s.viki.moe/v2/weather/realtime'
    response = requests.get(url, params={'location': location})
    return response.json()

Example

Example

weather = get_realtime_weather('北京') print(f"☁️ {weather['location']}天气") print(f"🌡️ 温度:{weather['temperature']}°C") print(f"💨 风速:{weather['wind']}") print(f"💧 湿度:{weather['humidity']}")
undefined
weather = get_realtime_weather('北京') print(f"☁️ {weather['location']}天气") print(f"🌡️ 温度:{weather['temperature']}°C") print(f"💨 风速:{weather['wind']}") print(f"💧 湿度:{weather['humidity']}")
undefined

Get Weather Forecast

获取天气预报

python
def get_weather_forecast(location):
    url = 'https://60s.viki.moe/v2/weather/forecast'
    response = requests.get(url, params={'location': location})
    return response.json()
python
def get_weather_forecast(location):
    url = 'https://60s.viki.moe/v2/weather/forecast'
    response = requests.get(url, params={'location': location})
    return response.json()

Example

Example

forecast = get_weather_forecast('上海') for day in forecast['forecast']: print(f"{day['date']}: {day['weather']} {day['temp_low']}°C ~ {day['temp_high']}°C")
undefined
forecast = get_weather_forecast('上海') for day in forecast['forecast']: print(f"{day['date']}: {day['weather']} {day['temp_low']}°C ~ {day['temp_high']}°C")
undefined

Simple bash example

Bash简单示例

bash
undefined
bash
undefined

Real-time weather

Real-time weather

Weather forecast

Weather forecast

Response Format

返回格式

Real-time Weather Response

实时天气返回结果

json
{
  "location": "北京",
  "weather": "晴",
  "temperature": "15",
  "humidity": "45%",
  "wind": "东北风3级",
  "air_quality": "良",
  "updated": "2024-01-15 14:00:00"
}
json
{
  "location": "北京",
  "weather": "晴",
  "temperature": "15",
  "humidity": "45%",
  "wind": "东北风3级",
  "air_quality": "良",
  "updated": "2024-01-15 14:00:00"
}

Forecast Response

天气预报返回结果

json
{
  "location": "上海",
  "forecast": [
    {
      "date": "2024-01-15",
      "day_of_week": "星期一",
      "weather": "多云",
      "temp_low": "10",
      "temp_high": "18",
      "wind": "东风3-4级"
    },
    ...
  ]
}
json
{
  "location": "上海",
  "forecast": [
    {
      "date": "2024-01-15",
      "day_of_week": "星期一",
      "weather": "多云",
      "temp_low": "10",
      "temp_high": "18",
      "wind": "东风3-4级"
    },
    ...
  ]
}

Example Interactions

示例交互

User: "北京今天天气怎么样?"

用户:"北京今天天气怎么样?"

Agent Response:
python
weather = get_realtime_weather('北京')
response = f"""
☁️ 北京今日天气

天气状况:{weather['weather']}
🌡️ 温度:{weather['temperature']}°C
💧 湿度:{weather['humidity']}
💨 风力:{weather['wind']}
🌫️ 空气质量:{weather['air_quality']}
"""
Agent响应:
python
weather = get_realtime_weather('北京')
response = f"""
☁️ 北京今日天气

天气状况:{weather['weather']}
🌡️ 温度:{weather['temperature']}°C
💧 湿度:{weather['humidity']}
💨 风力:{weather['wind']}
🌫️ 空气质量:{weather['air_quality']}
"""

User: "上海未来三天天气"

用户:"上海未来三天天气"

python
forecast = get_weather_forecast('上海')
response = "📅 上海未来天气预报\n\n"
for day in forecast['forecast'][:3]:
    response += f"{day['date']} {day['day_of_week']}\n"
    response += f"  {day['weather']} {day['temp_low']}°C ~ {day['temp_high']}°C\n"
    response += f"  {day['wind']}\n\n"
python
forecast = get_weather_forecast('上海')
response = "📅 上海未来天气预报\n\n"
for day in forecast['forecast'][:3]:
    response += f"{day['date']} {day['day_of_week']}\n"
    response += f"  {day['weather']} {day['temp_low']}°C ~ {day['temp_high']}°C\n"
    response += f"  {day['wind']}\n\n"

User: "深圳会下雨吗?"

用户:"深圳会下雨吗?"

python
weather = get_realtime_weather('深圳')
if '雨' in weather['weather']:
    print("☔ 是的,深圳现在正在下雨")
    print("建议带伞出门!")
else:
    forecast = get_weather_forecast('深圳')
    rain_days = [d for d in forecast['forecast'] if '雨' in d['weather']]
    if rain_days:
        print(f"未来{rain_days[0]['date']}可能会下雨")
    else:
        print("近期没有降雨预报")
python
weather = get_realtime_weather('深圳')
if '雨' in weather['weather']:
    print("☔ 是的,深圳现在正在下雨")
    print("建议带伞出门!")
else:
    forecast = get_weather_forecast('深圳')
    rain_days = [d for d in forecast['forecast'] if '雨' in d['weather']]
    if rain_days:
        print(f"未来{rain_days[0]['date']}可能会下雨")
    else:
        print("近期没有降雨预报")

Best Practices

最佳实践

  1. Location Names: Always use Chinese characters for location names
  2. Error Handling: Check if the location is valid before displaying results
  3. Context: Provide relevant context based on weather conditions
    • Rain: Suggest bringing umbrella
    • Hot: Recommend staying hydrated
    • Cold: Advise wearing warm clothes
    • Poor AQI: Suggest wearing mask
  4. Caching: Weather data is updated regularly but can be cached for short periods
  5. Fallbacks: If a specific district doesn't work, try the city name
  1. 地点名称: 始终使用中文汉字作为地点名称
  2. 错误处理: 在展示结果前,检查地点是否有效
  3. 场景建议: 根据天气状况提供相关建议
    • 雨天:建议携带雨伞
    • 高温:建议及时补充水分
    • 寒冷:建议注意保暖
    • 空气质量差:建议佩戴口罩
  4. 缓存: 天气数据会定期更新,但可进行短时间缓存
  5. 降级方案: 如果特定区/县无法查询,尝试使用城市名称

Common Use Cases

常见使用场景

1. Weather-based Recommendations

1. 基于天气的建议

python
def give_weather_advice(location):
    weather = get_realtime_weather(location)
    advice = []
    
    temp = int(weather['temperature'])
    if temp > 30:
        advice.append("🔥 天气炎热,注意防暑降温,多喝水")
    elif temp < 5:
        advice.append("🥶 天气寒冷,注意保暖")
    
    if '雨' in weather['weather']:
        advice.append("☔ 记得带伞")
    
    if weather['air_quality'] in ['差', '重度污染']:
        advice.append("😷 空气质量不佳,建议戴口罩")
    
    return '\n'.join(advice)
python
def give_weather_advice(location):
    weather = get_realtime_weather(location)
    advice = []
    
    temp = int(weather['temperature'])
    if temp > 30:
        advice.append("🔥 天气炎热,注意防暑降温,多喝水")
    elif temp < 5:
        advice.append("🥶 天气寒冷,注意保暖")
    
    if '雨' in weather['weather']:
        advice.append("☔ 记得带伞")
    
    if weather['air_quality'] in ['差', '重度污染']:
        advice.append("😷 空气质量不佳,建议戴口罩")
    
    return '\n'.join(advice)

2. Multi-city Weather Comparison

2. 多城市天气对比

python
def compare_weather(cities):
    results = []
    for city in cities:
        weather = get_realtime_weather(city)
        results.append({
            'city': city,
            'temperature': int(weather['temperature']),
            'weather': weather['weather']
        })
    
    # Find hottest and coldest
    hottest = max(results, key=lambda x: x['temperature'])
    coldest = min(results, key=lambda x: x['temperature'])
    
    return f"🌡️ 最热: {hottest['city']} {hottest['temperature']}°C\n" \
           f"❄️ 最冷: {coldest['city']} {coldest['temperature']}°C"
python
def compare_weather(cities):
    results = []
    for city in cities:
        weather = get_realtime_weather(city)
        results.append({
            'city': city,
            'temperature': int(weather['temperature']),
            'weather': weather['weather']
        })
    
    # Find hottest and coldest
    hottest = max(results, key=lambda x: x['temperature'])
    coldest = min(results, key=lambda x: x['temperature'])
    
    return f"🌡️ 最热: {hottest['city']} {hottest['temperature']}°C\n" \
           f"❄️ 最冷: {coldest['city']} {coldest['temperature']}°C"

3. Travel Weather Check

3. 出行天气检查

python
def check_travel_weather(destination, days=3):
    forecast = get_weather_forecast(destination)
    suitable_days = []
    
    for day in forecast['forecast'][:days]:
        if '雨' not in day['weather'] and '雪' not in day['weather']:
            suitable_days.append(day['date'])
    
    if suitable_days:
        return f"✅ {destination}适合出行的日期:{', '.join(suitable_days)}"
    else:
        return f"⚠️ 未来{days}{destination}天气不太适合出行"
python
def check_travel_weather(destination, days=3):
    forecast = get_weather_forecast(destination)
    suitable_days = []
    
    for day in forecast['forecast'][:days]:
        if '雨' not in day['weather'] and '雪' not in day['weather']:
            suitable_days.append(day['date'])
    
    if suitable_days:
        return f"✅ {destination}适合出行的日期:{', '.join(suitable_days)}"
    else:
        return f"⚠️ 未来{days}{destination}天气不太适合出行"

Troubleshooting

问题排查

Issue: Location not found

问题:未找到地点

  • Solution: Try using the main city name instead of district
  • Example: Use "北京" instead of "朝阳区"
  • 解决方案: 尝试使用主城市名称而非区/县名称
  • 示例:使用"北京"而非"朝阳区"

Issue: No forecast data

问题:无预报数据

  • Solution: Verify the location name is correct
  • Try standard city names: 北京, 上海, 广州, 深圳, etc.
  • 解决方案: 确认地点名称正确
  • 尝试使用标准城市名称:北京、上海、广州、深圳等

Issue: Data seems outdated

问题:数据似乎已过期

  • Solution: The API updates regularly, but weather can change quickly
  • Check the
    updated
    timestamp in the response
  • 解决方案: API会定期更新数据,但天气变化较快
  • 检查返回结果中的
    updated
    时间戳

Supported Locations

支持的地区

The weather API supports most cities and districts in China, including:
  • Provincial capitals: 北京, 上海, 广州, 深圳, 成都, 杭州, 南京, 武汉, etc.
  • Major cities: 苏州, 青岛, 大连, 厦门, etc.
  • Districts: 海淀区, 朝阳区, 浦东新区, etc.
该天气API支持中国境内大部分城市和区/县,包括:
  • 省会城市:北京、上海、广州、深圳、成都、杭州、南京、武汉等
  • 主要城市:苏州、青岛、大连、厦门等
  • 区/县:海淀区、朝阳区、浦东新区等

Related Resources

相关资源