Input a city name, get real-time weather forecasts and smart outfit recommendations. 输入城市名称,获取实时天气预报和智能穿搭建议
- Multi-source Weather Data: Supports Open-Meteo (free, no API key) and HeFeng Weather (paid API)
- Smart Outfit Suggestions: Professional clothing recommendations based on temperature and weather conditions
- 7-Day Forecast Charts: Auto-generated temperature trend and precipitation visualization
- Global City Support: Supports Chinese and English city names with automatic conversion
- Natural Language Queries: Supports formats like "Beijing weather", "London weather怎么样"
- Web Interface: Feature-rich web client with quick city buttons
weather_agent/
├── config.py # Configuration (API keys, URLs, constants)
├── utils/ # Utility modules
│ ├── __init__.py
│ ├── chinese_util.py # Chinese text processing (pinyin, city mapping)
│ └── weather_codes.py # WMO weather code mapping
├── api/ # Weather API layer
│ ├── __init__.py
│ ├── weather_base.py # Abstract base class for weather providers
│ ├── hefeng_api.py # HeFeng Weather API implementation
│ └── openmeteo_api.py # Open-Meteo API implementation
├── core/ # Core business logic
│ ├── __init__.py
│ ├── weather_analyzer.py # Weather data analysis
│ └── outfit_suggester.py # Outfit suggestion generation
├── visualization/ # Visualization module
│ ├── __init__.py
│ └── chart_generator.py # Chart generation with matplotlib
├── web_app.py # Flask Web application
├── weather_agent.py # CLI entry point
├── templates/ # HTML templates
│ └── index.html # Web interface template
└── requirements.txt # Python dependencies
| Category | Technology |
|---|---|
| Language | Python 3.8+ |
| Web Framework | Flask 2.0+ |
| HTTP Client | requests |
| Data Visualization | matplotlib |
| Chinese Pinyin | pypinyin |
| Weather APIs | Open-Meteo (free), HeFeng Weather (paid) |
- Python 3.8 or higher
- pip package manager
# Clone the project
git clone https://github.com/cang-ge/weather-agent.git
cd weather-agent
# Install dependencies
pip install -r requirements.txtpython web_app.pyThen open in browser: http://127.0.0.1:5000
# Query a single city
python weather_agent.py Beijing
# Interactive mode
python weather_agent.py北京天气 → Query Beijing weather
上海怎么样 → Query Shanghai weather
帮我查询广州的天气 → Query Guangzhou weather
杭州穿什么合适 → Query Hangzhou weather with outfit suggestions
Tokyo weather → Query Tokyo weather (English)
伦敦天气怎么样 → Query London weather (Chinese)
London weather → Query London weather (English)
Chinese Cities (by pinyin conversion): Beijing, Shanghai, Guangzhou, Shenzhen, Chengdu, Chongqing, Hangzhou, Wuhan, Xi'an, etc.
Foreign Cities (by name mapping): London, Paris, Tokyo, New York, Sydney, Berlin, Rome, Moscow, Dubai, Singapore, etc.
HeFeng Weather requires registration. To configure:
- Register at https://dev.heweather.com/
- Get your API Key
- Set environment variable:
# Linux/Mac
export HEFENG_API_KEY="your_api_key_here"
# Windows
set HEFENG_API_KEY=your_api_key_hereNote: Without HeFeng API, the program automatically uses Open-Meteo (free, no key required)
| API | Description | Cost |
|---|---|---|
| Open-Meteo | Primary data source, global city support | Free |
| HeFeng Weather | Optional advanced source | Limited free tier |
- Modularity: Each feature is an independent module with clear responsibilities
- Extensibility: Adding a new weather source only requires implementing the
WeatherProviderinterface - Centralized Configuration: All configuration is centrally managed
- Error Handling: Comprehensive exception catching and error reporting
MIT License
- Open-Meteo - Free weather API
- PyPinyin - Chinese pinyin conversion
- 多源天气数据: 支持 Open-Meteo(免费,无需API密钥)和和风天气(付费API)
- 智能穿搭建议: 根据温度和天气状况生成专业穿搭推荐
- 7天预报图表: 自动生成温度趋势和降水预报可视化图表
- 全球化城市支持: 支持中文和英文城市名,自动转换
- 自然语言查询: 支持多种格式,如"北京天气"、"伦敦天气怎么样"
- Web界面: 功能丰富的网页客户端,支持快捷城市按钮
weather_agent/
├── config.py # 配置管理(API密钥、URL、常量)
├── utils/ # 工具模块
│ ├── __init__.py
│ ├── chinese_util.py # 中文处理(拼音转换、城市映射)
│ └── weather_codes.py # WMO天气代码映射
├── api/ # 天气API接口层
│ ├── __init__.py
│ ├── weather_base.py # API基类(抽象接口)
│ ├── hefeng_api.py # 和风天气API实现
│ └── openmeteo_api.py # Open-Meteo API实现
├── core/ # 核心业务逻辑
│ ├── __init__.py
│ ├── weather_analyzer.py # 天气数据分析
│ └── outfit_suggester.py # 穿搭建议生成
├── visualization/ # 可视化模块
│ ├── __init__.py
│ └── chart_generator.py # 图表绘制(matplotlib)
├── web_app.py # Flask Web应用
├── weather_agent.py # CLI命令行入口
├── templates/ # HTML模板
│ └── index.html # Web界面模板
└── requirements.txt # Python依赖
| 分类 | 技术 |
|---|---|
| 语言 | Python 3.8+ |
| Web框架 | Flask 2.0+ |
| HTTP客户端 | requests |
| 数据可视化 | matplotlib |
| 中文拼音 | pypinyin |
| 天气API | Open-Meteo(免费)、和风天气(付费) |
- Python 3.8 或更高版本
- pip 包管理器
# 克隆项目
git clone https://github.com/cang-ge/weather-agent.git
cd weather-agent
# 安装依赖
pip install -r requirements.txtpython web_app.py然后在浏览器打开: http://127.0.0.1:5000
# 查询单个城市
python weather_agent.py 北京
# 交互模式
python weather_agent.py北京天气 → 查询北京天气
上海怎么样 → 查询上海天气
帮我查询广州的天气 → 查询广州天气
杭州穿什么合适 → 查询杭州天气并获取穿搭建议
Tokyo weather → 查询东京天气(英文)
伦敦天气怎么样 → 查询伦敦天气(中文)
London weather → 查询伦敦天气(英文)
中国城市(通过拼音转换): 北京、上海、广州、深圳、成都、重庆、杭州、武汉、西安等
外国城市(通过名称映射): 伦敦、巴黎、东京、纽约、悉尼、柏林、罗马、莫斯科、迪拜、新加坡等
和风天气需要注册获取API密钥。如需配置:
- 注册账号: https://dev.heweather.com/
- 获取API Key
- 设置环境变量:
# Linux/Mac
export HEFENG_API_KEY="your_api_key_here"
# Windows
set HEFENG_API_KEY=your_api_key_here注意: 不配置和风API时,程序将自动使用 Open-Meteo(免费无需API密钥)
| API | 说明 | 费用 |
|---|---|---|
| Open-Meteo | 主要数据源,支持全球城市 | 免费 |
| 和风天气 | 可选的高级数据源 | 免费额度有限 |
- 模块化: 每个功能独立成模块,职责清晰
- 可扩展性: 新增天气源只需实现
WeatherProvider接口 - 配置集中: 所有配置集中管理,便于维护
- 错误处理: 完善的异常捕获和错误提示
MIT License
- Open-Meteo - 免费天气API
- PyPinyin - 中文拼音转换