Weather is a Python-based command-line application designed with object-oriented principles that fetches and displays real-time weather information for any city using OpenWeatherMap API. It’s modular, clean, and secure by keeping API keys outside the code.
This app allows users to:
- Get real-time weather updates by city name
- Convert and display temperatures in Celsius
- Handle errors gracefully (invalid city, network issues)
- Securely manage API keys using environment variables (
.env
) - Easily extend functionality with OOP architecture
✅ Object-oriented design for maintainability and extensibility
✅ Real-time weather data from OpenWeatherMap API
✅ API key security via .env
and python-dotenv
✅ Clear terminal output
✅ Modular code structure for easy upgrades (forecast, GUI, etc.)
✅ Minimal external dependencies
Technology | Purpose |
---|---|
Python 3 | Core programming language |
requests |
HTTP requests to fetch API data |
python-dotenv |
Load environment variables from .env |
JSON (built-in) | Parse API responses |
- Python 3.7 or newer
- OpenWeatherMap API key (https://openweathermap.org/api)
-
Clone the repo:
git clone https://github.com/sade6h/weather.git cd weather
-
(Optional) Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Create
.env
file in the project root with:API_KEY=your_openweathermap_api_key
-
Run the app:
python app.py
Please enter the city name: Tehran
Tehran Temperature: 26.34°C
weather/
├── app.py # Main OOP app entry point
├── config.py # API config constants
├── weather_service.py # WeatherService class (API requests)
├── requirements.txt # Dependencies list
├── .env.example # Sample environment variables file
└── README.md # This file
- Add multi-day weather forecast
- Add humidity, wind speed, and description display
- Integrate IP-based location detection
- Build GUI (tkinter, streamlit)
- Add export (JSON/CSV) functionality
- Add multilingual support
Feel free to fork, modify, and submit pull requests! Make sure to create feature branches and describe your changes.
Developed by @sade6h ☕ Star ⭐ if you find it useful!
This project is licensed under the MIT License.
⚠️ Note: Keep your.env
file secret! Never push it to public repositories.