mcpField
W
weather-query

weather-query

github.com/vikiboss其他47825 次安装34 周前更新
代码仓库

关于 weather-query

weather-query 是供 AI Agent 使用的天气查询技能,通过 60s API 获取中国地点的实时天气和预报,包含空气质量等信息。

主要功能

  1. 01查询实时天气
  2. 02获取天气预报
  3. 03查看温度、湿度和风力
  4. 04查询空气质量
  5. 05支持中国城市及区县

适用场景

  1. 01回答某地当前天气问题
  2. 02查看未来天气以安排户外活动
  3. 03比较多个城市的天气
  4. 04查询旅行目的地天气

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/vikiboss/60s-skills --skill weather-query

安装后在 Claude Code 中输入/weather-query确认已加载。

详细介绍

天气查询技能

此技能可帮助 AI Agent 使用 60s API 获取中国各地的实时天气信息和天气预报。

何时使用此技能

在用户:

  • 询问当前天气状况时
  • 想要查看天气预报时
  • 需要了解温度、湿度或风力信息时
  • 请求空气质量数据时
  • 计划户外活动并需要了解天气信息时

API 端点

1. 实时天气

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

2. 天气预报

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

参数

  • query(必填):中文地名
    • 可以是城市名:"北京"、"上海"、"广州"
    • 可以是区县名:"海淀区"、"浦东新区"

使用方法

获取实时天气
import requests

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

# Example
weather = get_realtime_weather('北京')
print(f"☁️ {weather['location']}天气")
print(f"🌡️ 温度:{weather['temperature']}°C")
print(f"💨 风速:{weather['wind']}")
print(f"💧 湿度:{weather['humidity']}")
获取天气预报
def get_weather_forecast(query):
    url = 'https://60s.viki.moe/v2/weather/forecast'
    response = requests.get(url, params={'query': query})
    return response.json()

# Example
forecast = get_weather_forecast('上海')
for day in forecast['forecast']:
    print(f"{day['date']}: {day['weather']} {day['temp_low']}°C ~ {day['temp_high']}°C")
简单的 bash 示例
# Real-time weather
curl "https://60s.viki.moe/v2/weather/realtime?query=北京"

# Weather forecast
curl "https://60s.viki.moe/v2/weather/forecast?query=上海"

响应格式

实时天气响应
{
  "location": "北京",
  "weather": "晴",
  "temperature": "15",
  "humidity": "45%",
  "wind": "东北风3级",
  "air_quality": "良",
  "updated": "2024-01-15 14:00:00"
}
天气预报响应
{
  "location": "上海",
  "forecast": [
    {
      "date": "2024-01-15",
      "day_of_week": "星期一",
      "weather": "多云",
      "temp_low": "10",
      "temp_high": "18",
      "wind": "东风3-4级"
    },
    ...
  ]
}

交互示例

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

Agent 回复:

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

天气状况:{weather['weather']}
🌡️ 温度:{weather['temperature']}°C
💧 湿度:{weather['humidity']}
💨 风力:{weather['wind']}
🌫️ 空气质量:{weather['air_quality']}
"""
用户:"上海未来三天天气"
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"
用户:"深圳会下雨吗?"
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("近期没有降雨预报")

最佳实践

  1. 地名:地名始终使用中文字符

  2. 错误处理:显示结果前,先检查地名是否有效

  3. 上下文:根据天气状况提供相关提示

    • 下雨:建议带伞
    • 天气炎热:建议及时补充水分
    • 天气寒冷:建议穿暖和的衣服
    • AQI 较差:建议戴口罩
  4. 缓存:天气数据会定期更新,但可以短时间缓存

  5. 备用方案:如果无法查询特定区县,尝试使用城市名

常见使用场景

1. 基于天气的建议
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. 多城市天气对比
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. 出行天气查询
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}天气不太适合出行"

故障排查

问题:找不到地名
  • 解决方案:尝试使用城市名,而非区县名
  • 示例:使用"北京"代替"朝阳区"
问题:没有天气预报数据
  • 解决方案:确认地名是否正确
  • 尝试使用标准城市名:北京、上海、广州、深圳等
问题:数据似乎已过时
  • 解决方案:API 会定期更新,但天气可能变化很快
  • 检查响应中的 updated 时间戳

支持的地区

天气 API 支持中国大多数城市和区县,包括:

  • 省级行政中心:北京、上海、广州、深圳、成都、杭州、南京、武汉等
  • 主要城市:苏州、青岛、大连、厦门等
  • 区县:海淀区、朝阳区、浦东新区等

相关资源

评论

支持 Markdown