A fully functional Python weather application that fetches real-time weather data and forecasts using the OpenWeatherMap API...
✅ Current Weather: Get real-time weather information for any city
- Temperature (actual and "feels like")
- Weather conditions
- Humidity and pressure
- Wind speed
- Sunrise and sunset times
✅ Weather Forecast: Get 5-day weather forecasts
- Hourly breakdown for the first 24 hours
- Temperature trends
- Weather conditions
- Humidity tracking
✅ User-Friendly Interface: Interactive menu system
✅ Error Handling: Robust error handling for API requests
cd /workspaces/codespaces-blank/weather-apppip install -r requirements.txt- Go to OpenWeatherMap API
- Sign up for a free account
- Get your API key from the dashboard
- Copy your API key
Edit main.py and replace the API_KEY value:
API_KEY = "your_actual_api_key_here"Or create a .env file:
cp .env.example .envThen edit .env and add your actual API key.
Run the application:
python main.pyThe application will present a menu with options:
- Get current weather - Enter a city name to see current conditions
- Get weather forecast - Enter a city name to see the 5-day forecast
- Exit - Close the application
Enter city name: London
Enter city name: New York
Enter city name: Tokyo
The application uses an object-oriented approach with the WeatherApp class:
__init__(api_key)- Initialize with your OpenWeatherMap API keyget_current_weather(city)- Fetch current weather dataget_forecast(city)- Fetch 5-day weather forecastdisplay_current_weather()- Format and display current weatherdisplay_forecast()- Format and display forecast data
Uses the free OpenWeatherMap API:
- Current Weather Endpoint:
/weather - Forecast Endpoint:
/forecast
- Converts Unix timestamps to readable dates/times
- Formats temperatures in Celsius (configurable)
- Groups forecast data by day
- Displays data in an easy-to-read format
- Language: Python 3.x
- Key Libraries:
requestsfor HTTP calls - Type Hints: Includes proper type annotations
- Error Handling: Try-except blocks for API failures
- Verify your API key is correct
- Check your internet connection
- Ensure the city name is valid
- Sign up for a free account at openweathermap.org
- Wait a few minutes after registration for the key to activate
- Check that you copied the entire key correctly
- Check your internet connection
- Verify the OpenWeatherMap API is not down
- Try a different city
- Add caching to reduce API calls
- Store favorite cities
- Add weather alerts
- Support for coordinates (latitude/longitude)
- Export data to CSV/JSON
- Add weather icons/emojis for conditions
- Background tasks for periodic updates
- Web UI using Flask/Django
This project is open source and available for educational purposes.
. Enjoy using the Weather Forecast Application! 🌤️