This repository showcases my project on creating a Telegram bot focused on weather forecasting, powered by the OpenWeather API using Python. It serves as an excellent learning opportunity for understanding API interactions and building a practical Telegram bot.
-
OpenWeather API Integration: The bot uses the OpenWeather API to provide real-time weather information for different cities.
-
Interactive Telegram Experience: Users can receive weather forecasts for predefined cities or input a specific city name directly.
Before running the bot, ensure you have the following:
-
OpenWeather API Key: Obtain your API key from OpenWeather and save it in a file named OWM_key.txt
-
Telegram Bot Token: Create a Telegram bot and get your bot token. Save the token in a file named token.txt
Note: Make sure to keep both files (OWM_key.txt and token.txt) private and never share them publicly.
In this project i created the files empty, so you can try it locally.
To run the bot, follow these simple steps:
Clone the repository:
git clone https://github.com/ArnauCS03/Weather-Forecast-Telegram-Bot.git
cd Weather-Forecast-Telegram-Bot
Install the required Python packages:
pip3 install python-telegram-bot requests
Place your OpenWeather API key in OWM_key.txt and your Telegram bot token in token.txt.
Run the bot script:
python3 OpenWeather.py
Once the bot is running, you can interact with it on Telegram:
-
Start the bot by sending /start to get a list of predefined cities and weather information.
-
Type the name of a city to get the current weather conditions directly or clik one of the cities predefined.
To learn the basics of creating your first simple Telegram bot, check out this tutorial: Lliçons Jutge Telegram
You can access the bot on Telegram by following this link: PrevisioTempsBot. Please note that it might not respond since the Python script is not currently running.
Feel free to explore the code, learn from it, and customize it to suit your needs.