A Python Telegram bot that fetches real-time weather data from OpenWeatherMap and automatically delivers hourly reports to your Telegram chat using APScheduler.
Telegram Weather Bot is a Python-based bot that connects the Telegram Bot API with the OpenWeatherMap API to deliver real-time weather updates for Dhaka, Bangladesh (configurable to any city). Once started, the bot automatically pushes a full weather report to your Telegram chat every hour using a background scheduler - no manual trigger needed. It also responds to on-demand commands for instant updates and control.
- ๐ก Real-time weather data: temperature, humidity, wind speed, pressure, visibility, and weather condition
- โฑ๏ธ Hourly auto-reports: APScheduler pushes updates every hour without any user action
- ๐ค Bot commands: full control via
/start,/stop, and/test - ๐ City-configurable: defaults to Dhaka, Bangladesh; change to any city in one line
- ๐ Secure API keys: credentials loaded from environment variables, never hardcoded
- ๐ชถ Lightweight: no database, no web server; just Python running in the background
| Command | Action |
|---|---|
/start |
Begin receiving hourly weather reports |
/stop |
Stop the hourly weather schedule |
/test |
Get an immediate weather report and confirm the bot is alive |
Each report includes the following live data from OpenWeatherMap:
| Field | Description |
|---|---|
| ๐ก๏ธ Temperature | Current temp in ยฐC |
| ๐ก๏ธ Feels Like | Perceived temperature |
| ๐ง Humidity | Relative humidity (%) |
| ๐จ Wind Speed | Speed in m/s |
| ๐ฌ๏ธ Pressure | Atmospheric pressure (hPa) |
| ๐๏ธ Visibility | Visibility in metres |
| โ๏ธ Condition | Sky condition (e.g., Clear, Cloudy, Rain) |
User sends /start on Telegram
โ
โผ
pyTelegramBotAPI receives the command
โ
โผ
APScheduler starts a background job
โ (runs every 60 minutes)
โผ
OpenWeatherMap API called
โ โ Returns live JSON weather data
โผ
Bot formats the weather message
โ
โผ
Message sent to user's Telegram chat โ
/stop cancels the scheduled job. /test triggers a single immediate fetch outside the schedule.
| Tool | Purpose |
|---|---|
Python 3 |
Core language |
pyTelegramBotAPI |
Telegram bot API wrapper |
APScheduler |
Background hourly job scheduler |
OpenWeatherMap API |
Real-time weather data source |
requests |
HTTP calls to the weather API |
- Python 3.7+
pyTelegramBotAPIAPSchedulerrequests
Telegram Bot Token
- Open Telegram and message @BotFather
- Send
/newbotand follow the prompts - Copy your bot token
OpenWeatherMap API Key
- Sign up at openweathermap.org
- Go to API Keys in your account dashboard
- Copy your free API key
git clone https://github.com/MusaIslamFahad/telegram-weather-bot.git
cd telegram-weather-botpip install pyTelegramBotAPI APScheduler requestsOption A: Export directly (Linux / macOS)
export BOT_TOKEN="your_telegram_bot_token"
export WEATHER_API_KEY="your_openweathermap_api_key"Option B: Set in terminal (Windows CMD)
set BOT_TOKEN=your_telegram_bot_token
set WEATHER_API_KEY=your_openweathermap_api_keyOption C: Use a .env file (recommended)
Create a .env file in the project root:
BOT_TOKEN=your_telegram_bot_token
WEATHER_API_KEY=your_openweathermap_api_key
Then install python-dotenv and load it at the top of the script:
from dotenv import load_dotenv
load_dotenv()
โ ๏ธ Security: Always add.envto your.gitignoreโ never commit API keys to GitHub.
python "Telegram_bot/Telegram Weather Bot.py"Then open Telegram, find your bot, and send /start.
In the bot script, find the API call and update the city name:
city = "Dhaka" # Change to any city, e.g. "London", "Tokyo", "New York"In the APScheduler configuration, update the interval (in minutes):
scheduler.add_job(send_weather, 'interval', minutes=60)
# Change 60 to any value, e.g. 30 for every 30 minutestelegram-weather-bot/
โ
โโโ Telegram_bot/
โ โโโ Telegram Weather Bot.py # Main bot script
โ
โโโ .env # API keys โ DO NOT commit (add to .gitignore)
โโโ .gitignore
โโโ screenshots/ # README screenshots
โโโ README.md
Recommended .gitignore:
.env
__pycache__/
*.pyc
- ๐ Multi-city support: let users request weather for any city via command
- โฐ Custom intervals: allow users to set their own update frequency from Telegram
- ๐ Forecast reports: add 3-day or 7-day weather forecasts
- ๐ Inline queries: quick city lookups without switching to the bot chat
- ๐ณ Docker support: containerize for easy deployment on any server
- โ๏ธ Cloud deployment: host on AWS / Heroku / Railway so the bot runs 24/7 without keeping your PC on
Contributions and suggestions are welcome!
- Fork the repository
- Create a feature branch (
git checkout -b feature/your-feature) - Commit your changes (
git commit -m 'Add your feature') - Push to the branch (
git push origin feature/your-feature) - Open a Pull Request
- pyTelegramBotAPI โ for the clean and simple Telegram bot wrapper
- OpenWeatherMap โ for the reliable free weather API
- APScheduler โ for straightforward background task scheduling
Musa Islam Fahad
- GitHub: @MusaIslamFahad
โญ If you found this useful or built something cool on top of it, drop a star. It helps a lot!