Weather App using Python (Console Based)
Introduction:
This Weather App is a simple command-line application built with Python. It uses real-time data from
the OpenWeatherMap API to provide weather updates like temperature, humidity, and conditions for
any city. This project is designed for Diploma 3rd Semester CSE students to demonstrate API
handling and JSON parsing using Python.
Requirements:
- Python 3.x
- requests module (install using: pip install requests)
- OpenWeatherMap API key (Free registration at https://openweathermap.org)
- Internet connection
Features:
- Input city name and get current weather
- Displays temperature in Celsius
- Shows weather condition, humidity, and wind speed
Python Code:
import requests
def get_weather(city_name, api_key):
url =
f"http://api.openweathermap.org/data/2.5/weather?q={city_name}&appid={api_key}&units=met
ric"
response = requests.get(url)
if response.status_code == 200:
data = response.json()
print(f"\nWeather Report for {city_name}:")
print(f"Temperature: {data['main']['temp']}°C")
print(f"Condition: {data['weather'][0]['description']}")
print(f"Humidity: {data['main']['humidity']}%")
print(f"Wind Speed: {data['wind']['speed']} m/s")
else:
print("City not found or invalid API key.")
if __name__ == "__main__":
api_key = "your_api_key_here" # Replace with your actual API key
city = input("Enter city name: ")
get_weather(city, api_key)
Conclusion:
This basic weather app showcases how to build a real-world application using Python and REST
APIs. With further improvements, students can create a GUI version using Tkinter or add 5-day
forecasts.