Install
openclaw skills install @ruiduobao/china-weather-dataQuery China meteorological station data from data.cma.cn (authenticated) or Open-Meteo (free fallback). Supports temperature, precipitation, wind, pressure, humidity, and sunshine data. Outputs CSV or JSON.
openclaw skills install @ruiduobao/china-weather-dataQuery and download China meteorological station data. Supports two data sources:
# Query by city (uses Open-Meteo)
python scripts\china-weather-data.py query --city Beijing --start 2020-01-01 --end 2020-01-31
# Query by coordinates
python scripts\china-weather-data.py query --lat 39.9042 --lon 116.4074 --start 2020-01-01 --end 2020-12-31 --type temperature
# Download to CSV
python scripts\china-weather-data.py download --city Shanghai --start 2020-06-01 --end 2020-08-31 --output shanghai_summer.csv
# List stations
python scripts\china-weather-data.py list-stations --province Guangdong
# Configure API key for data.cma.cn
python scripts\china-weather-data.py configure --key YOUR_API_KEY
pip install requests>=2.28.0 tqdm
# Or: pip install -r scripts/requirements.txt
query / download| Argument | Required | Default | Description |
|---|---|---|---|
--city | No* | — | City name (e.g., "Beijing") |
--station | No* | — | Station ID (data.cma.cn) |
--lat | No* | — | Latitude (for Open-Meteo) |
--lon | No* | — | Longitude (for Open-Meteo) |
--start | Yes | — | Start date (YYYY-MM-DD) |
--end | Yes | — | End date (YYYY-MM-DD) |
--type | No | all | Data type: temperature, precipitation, wind, pressure, humidity, sunshine |
--json | No | false | Output as JSON |
--output | download only | — | Output file path |
list-stations| Argument | Required | Default | Description |
|---|---|---|---|
--province | No | — | Filter by province name |
--json | No | false | Output as JSON |
configure| Argument | Required | Default | Description |
|---|---|---|---|
--key | Yes | — | API key for data.cma.cn |
python scripts\china-weather-data.py configure --key YOUR_KEY| Source | Resolution | Description |
|---|---|---|
| data.cma.cn | Hourly, Daily, Monthly | Station observations |
| Open-Meteo | Hourly, Daily | Gridded reanalysis/forecast |
| Data Type | Unit |
|---|---|
| Temperature | °C (摄氏度) |
| Precipitation | mm (毫米) |
| Wind speed | m/s (米/秒) |
| Pressure | hPa (百帕) |
| Humidity | % (相对湿度) |
| Sunshine | hours (小时) |
The tool automatically falls back to Open-Meteo when:
date,temperature,precipitation,wind_speed,pressure,humidity
2020-01-01,2.3,0.0,3.1,1013.2,45
2020-01-02,3.1,0.5,2.8,1012.8,52
2020-01-03,1.8,0.0,4.2,1014.1,40
data.cma.cn:
@misc{chinameteorological,
title = {China Meteorological Data Service},
author = {{China Meteorological Administration}},
howpublished = {\url{http://data.cma.cn/}},
note = {Accessed: YYYY-MM-DD}
}
Open-Meteo:
@misc{openmeteo2022,
title = {Open-Meteo API},
author = {{Open-Meteo}},
year = {2022},
howpublished = {\url{https://open-meteo.com/}},
note = {Accessed: YYYY-MM-DD}
}
plt.plot(dates, temperature) for temperature trendsmatplotlib subplots for comparing variablescalmap for seasonal patternswindrose package for wind direction/speed| Error | Cause | Solution |
|---|---|---|
ConnectionError | Network issue | Check internet, retry |
HTTP 429 | Rate limit | Wait 60s, retry |
ValueError | Invalid input | Check parameter format |
| Empty output | No data | Try different parameters |
ModuleNotFoundError | Missing dep | Run pip install |
HTTP 403 | No API key | Configure key or use Open-Meteo fallback |
| City not found | Name mismatch | Try pinyin or Chinese characters |
| Timeout | Slow API | Increase timeout or use fallback |
# Query multiple cities from a list
for city in "北京" "上海" "广州" "成都"; do
python scripts\china-weather-data.py download --city "$city" --type temperature --start 2023-01-01 --end 2023-12-31 --output weather_${city}_2023.csv
sleep 1
done
# .github/workflows/update-weather.yml
name: Update Weather Data
on:
schedule:
- cron: '0 7 * * *' # Daily at 07:00 Beijing time
jobs:
download:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- run: pip install requests
- env:
CMA_API_KEY: ${{ secrets.CMA_API_KEY }}
run: |
python scripts\china-weather-data.py download \
--city 北京 --type temperature \
--start $(date -d '7 days ago' +%Y-%m-%d) \
--end $(date +%Y-%m-%d) \
--output data/beijing_temp.csv
python scripts\china-weather-data.py download --city 北京 --type temperature --start 2023-01-01 --end 2023-12-31 --output weather.csv
psql -d gis_db -c "\COPY weather(city, date, temperature) FROM 'weather.csv' CSV HEADER"
sleep 1 between city queries to respect rate limits--force-openmeteo when CMA API is unavailable查询和下载中国气象站数据。支持两个数据源:
# 按城市查询(使用 Open-Meteo)
python scripts\china-weather-data.py query --city Beijing --start 2020-01-01 --end 2020-01-31
# 按坐标查询
python scripts\china-weather-data.py query --lat 39.9042 --lon 116.4074 --start 2020-01-01 --end 2020-12-31 --type temperature
# 下载到 CSV
python scripts\china-weather-data.py download --city Shanghai --start 2020-06-01 --end 2020-08-31 --output shanghai_summer.csv
# 列出站点
python scripts\china-weather-data.py list-stations --province Guangdong
# 配置 data.cma.cn API 密钥
python scripts\china-weather-data.py configure --key YOUR_API_KEY
python scripts\china-weather-data.py configure --key YOUR_KEY| 数据源 | 分辨率 | 说明 |
|---|---|---|
| data.cma.cn | 逐时、逐日、逐月 | 站点观测 |
| Open-Meteo | 逐时、逐日 | 格点再分析/预报 |
| 数据类型 | 单位 |
|---|---|
| 温度 | °C(摄氏度) |
| 降水 | mm(毫米) |
| 风速 | m/s(米/秒) |
| 气压 | hPa(百帕) |
| 湿度 | %(相对湿度) |
| 日照 | hours(小时) |
以下情况自动回退到 Open-Meteo:
date,temperature,precipitation,wind_speed,pressure,humidity
2020-01-01,2.3,0.0,3.1,1013.2,45
2020-01-02,3.1,0.5,2.8,1012.8,52
2020-01-03,1.8,0.0,4.2,1014.1,40
data.cma.cn:
@misc{chinameteorological,
title = {China Meteorological Data Service},
author = {{China Meteorological Administration}},
howpublished = {\url{http://data.cma.cn/}},
note = {Accessed: YYYY-MM-DD}
}
Open-Meteo:
@misc{openmeteo2022,
title = {Open-Meteo API},
author = {{Open-Meteo}},
year = {2022},
howpublished = {\url{https://open-meteo.com/}},
note = {Accessed: YYYY-MM-DD}
}
plt.plot(dates, temperature) 绘制温度趋势matplotlib subplots 比较不同变量calmap 创建日历热力图显示季节模式windrose 包绘制风向/风速| 错误 | 原因 | 解决方案 |
|---|---|---|
ConnectionError | 网络问题 | 检查网络,重试 |
HTTP 429 | 速率限制 | 等待 60 秒后重试 |
ValueError | 无效输入 | 检查参数格式 |
| 空输出 | 无数据 | 尝试不同参数 |
ModuleNotFoundError | 缺少依赖 | 运行 pip install |
HTTP 403 | 无 API 密钥 | 配置密钥或使用 Open-Meteo 回退 |
| 城市未找到 | 名称不匹配 | 尝试拼音或中文字符 |
| 超时 | API 响应慢 | 增加超时时间或使用回退 |