Skip to main content
Glama
ImDPS
by ImDPS
WEATHER_API_INTEGRATION.md4.54 kB
# Weather Tool - Open-Meteo API Integration ## Overview The weather tool has been enhanced to integrate with the [Open-Meteo API](https://open-meteo.com/) instead of using hardcoded data. This provides real-time, accurate weather information for cities worldwide. ## Features ### Real-Time Data - **Live weather data** from Open-Meteo's free weather API - **Current conditions** including temperature, humidity, wind, pressure, and visibility - **Weather codes** converted to human-readable descriptions - **Timestamp** showing when the data was last updated ### Enhanced Location Support - **Predefined coordinates** for 20+ major cities for fast lookups - **Geocoding support** for any city name using Open-Meteo's geocoding API - **Location aliases** (e.g., "NYC" → "New York", "LA" → "Los Angeles") - **Fuzzy matching** for partial city names ### Comprehensive Weather Information - **Temperature** in both Celsius and Fahrenheit - **Apparent temperature** (feels like) - **Weather conditions** (clear, cloudy, rainy, etc.) - **Humidity percentage** - **Wind speed and direction** in mph with compass direction - **Atmospheric pressure** in both hPa and inHg - **Visibility** in miles - **Precipitation** when present - **Cloud cover** percentage ## API Integration Details ### Open-Meteo Weather API - **Endpoint**: `https://api.open-meteo.com/v1/forecast` - **Parameters**: latitude, longitude, current weather variables - **Response**: JSON with current weather data - **Rate limits**: Free tier with generous limits ### Open-Meteo Geocoding API - **Endpoint**: `https://geocoding-api.open-meteo.com/v1/search` - **Parameters**: city name, language, count - **Response**: JSON with coordinates and location info - **Fallback**: Predefined coordinates for major cities ## Supported Cities ### Predefined Cities (Fast Lookup) - New York, London, Tokyo, Sydney, San Francisco - Paris, Berlin, Mumbai, Toronto, Dubai - Los Angeles, Chicago, Miami, Seattle, Boston - Austin, Denver, Phoenix, Las Vegas, Nashville ### Any City Worldwide The tool can fetch weather for any city by: 1. Using the geocoding API to find coordinates 2. Fetching weather data for those coordinates 3. Formatting the response with comprehensive information ## Usage Examples ```python # Basic usage weather = await weather_tool.get_weather("New York") # Location aliases weather = await weather_tool.get_weather("NYC") # → New York weather = await weather_tool.get_weather("LA") # → Los Angeles # Any city worldwide weather = await weather_tool.get_weather("Barcelona") weather = await weather_tool.get_weather("Cape Town") ``` ## Error Handling The tool includes robust error handling: - **Invalid locations**: Returns helpful error message - **API failures**: Graceful degradation with informative messages - **Network issues**: Timeout handling and retry logic - **Rate limiting**: Respectful API usage with delays ## Technical Implementation ### Async HTTP Client - Uses `aiohttp` for efficient async HTTP requests - Connection pooling and timeout management - Session reuse for better performance ### Data Processing - **Weather codes**: WMO standard codes converted to descriptions - **Unit conversions**: Celsius to Fahrenheit, km/h to mph, etc. - **Formatting**: Human-readable output with emojis and proper formatting ### Caching Strategy - **Predefined coordinates**: Fast lookup for major cities - **Session reuse**: Efficient HTTP connection management - **No data caching**: Always fresh weather data ## Dependencies - `aiohttp>=3.9.0` - Async HTTP client for API requests - Standard library modules: `asyncio`, `datetime`, `logging` ## Testing Run the test script to verify the integration: ```bash python3 test_weather_api.py ``` This will test multiple cities and error handling scenarios. ## Benefits Over Hardcoded Data 1. **Real-time accuracy**: Live weather data instead of static values 2. **Global coverage**: Any city worldwide, not just predefined ones 3. **Comprehensive data**: More weather variables than the original 4. **Reliability**: Professional weather API with high uptime 5. **Scalability**: Can handle any number of cities 6. **Maintenance**: No need to manually update weather data ## Future Enhancements - **Forecast support**: Add 7-day weather forecasts - **Historical data**: Weather history for analysis - **Weather alerts**: Severe weather notifications - **Multiple units**: Support for metric/imperial preferences - **Location caching**: Cache geocoding results for performance

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ImDPS/MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server