A Telegram bot that provides real-time weather information powered by the OpenWeather OneCall 3.0 API. It supports current conditions, multi-day forecasts, hourly forecasts, and weather alerts β all accessible via Telegram commands or a CLI tool.
The project is built with Python 3.12, aiogram 3.x, and can be easily integrated with OpenClaw for agent automation or LLM pipelines
- Features
- Project Structure
- Requirements
- Installation
- Configuration
- Running the Bot
- CLI Usage
- Telegram Commands
- Running Tests
- Architecture Overview
- π‘ Current weather β temperature, humidity, wind speed, and conditions.
- π Multi-day forecast β up to 8 days ahead.
- β± Hourly forecast β up to 48 hours ahead.
- π¨ Weather alerts β active alerts for any city.
- β‘ In-memory caching β 5-minute TTL to reduce API calls.
- π Auto-retry β exponential backoff on transient network errors.
- π³ Docker-ready β multi-stage Dockerfile with a non-root user.
- π₯ CLI interface β query weather directly from the terminal.
weather-bot/
βββ cli/
β βββ weather_cli.py # CLI entrypoint
βββ config/
β βββ config.yaml # App configuration (city, units, defaults)
βββ logs/ # Log output directory
βββ tests/
β βββ test_weather.py # Unit + integration tests (fully mocked)
β βββ helpers/
β βββ telegram_sender.py # Test helpers
βββ weather/
β βββ bot/
β β βββ main.py # Bot entrypoint (aiogram)
β β βββ handlers.py # Telegram command handlers
β βββ core/
β β βββ config.py # Settings loader (YAML + env vars)
β β βββ logging.py # Logger setup
β βββ skills/
β βββ weather/
β βββ client.py # Async OpenWeather API client
β βββ formatters.py # Response formatters
β βββ schema.py # Tool-call schema handler
β βββ skill.py # WeatherSkill core logic
βββ .env.sample # Environment variable template
βββ docker-compose.yml
βββ Dockerfile
βββ requirements.txt
- Python 3.12+
- A Telegram Bot Token (from @BotFather)
- An OpenWeather API Key with access to OneCall 3.0
# 1. Clone the repository
git clone https://github.com/afreisinger/weather-bot.git
cd weather-bot
# 2. Create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
# 3. Install dependencies
pip install -r requirements.txtCopy the sample file and fill in your credentials:
cp .env.sample .env| Variable | Description |
|---|---|
TELEGRAM_TOKEN |
Your Telegram Bot token |
OPENWEATHER_API_KEY |
Your OpenWeather API key |
CONFIG_PATH |
(Optional) Custom config file path |
weather:
default_city: "Buenos Aires"
units: "metric" # metric | imperial | standard
forecast_days: 3 # Default days for /forecast (1β8)
forecast_hours: 12 # Default hours for /forecast_hourly (1β48)export TELEGRAM_TOKEN=your_token
export OPENWEATHER_API_KEY=your_key
python -m weather.bot.main# Build
docker build -t weather-bot .
# Run
docker run --env-file .env -v $(pwd)/config:/app/config weather-botdocker compose up --buildThe
docker-compose.ymlmounts./configand./logsas volumes and automatically restarts the container on failure.
Query weather directly from your terminal without running the bot:
# Current weather
python -m cli.weather_cli current "London"
# 5-day forecast
python -m cli.weather_cli forecast "CΓ³rdoba" --days 5
# Enable debug logging
python -m cli.weather_cli -v current "Tokyo"| Command | Description |
|---|---|
/weather |
Current weather for the default city |
/weather <city> |
Current weather for a specific city |
/forecast |
3-day forecast for the default city |
/forecast <city> |
3-day forecast for a specific city |
/forecast <city> <days> |
Custom-day forecast (1β8 days) |
/forecast_hourly |
12-hour forecast for the default city |
/forecast_hourly <city> |
12-hour forecast for a specific city |
/forecast_hourly <city> <hours> |
Custom hourly forecast (1β48 hours) |
/alerts |
Active weather alerts for the default city |
/alerts <city> |
Active weather alerts for a specific city |
/help |
Show all available commands |
Tests are fully mocked β no real network calls or API keys are required.
# Install dev dependencies
pip install -r requirements-dev.txt
# Run all tests
pytest tests/ -v
# Run with coverage report
pytest tests/ -v --cov=weather --cov-report=term-missingTelegram User
β
βΌ
[aiogram Handlers] βββ weather/bot/handlers.py
β
βΌ
[WeatherSkill] βββ weather/skills/weather/skill.py
β
ββββΊ [Geocoding API] ββ
ββββΊ [OneCall 3.0 API] ββ€ββ weather/skills/weather/client.py
β (retry, cache, validation)
βΌ
[Formatters] βββ weather/skills/weather/formatters.py
β
βΌ
Formatted string response
WeatherSkillis transport-agnostic β it can be used by the Telegram bot, the CLI, or any other interface.client.pyhandles all HTTP communication with in-memory caching and exponential backoff retries.config.pymergesconfig.yamldefaults with environment variable overrides.
MIT License. See LICENSE for details.