A Python-based app that fetches real-time weather data using the OpenWeatherMap API.
A Python-based app that fetches real-time weather data using the OpenWeatherMap API.
git clone https://github.com/nagakirankasi/Weather-App.git
cd Weather-App
Ensure Python 3.8+ is installed, then run:
pip install -r requirements.txt
Example requirements.txt:
requests
streamlit
flask
matplotlib
Sign up at OpenWeatherMap and get a free API key.
Replace your_api_key in weather.py with your actual API key:
API_KEY = "your_api_key"
Run the script in command line mode:
python weather.py
Enter the city name when prompted, and the weather details will be displayed.
Launch the web interface:
streamlit run app.py
Use the input field to enter a city name and fetch weather data.
The app now fetches and displays a 5-day weather forecast, including:
BASE_FORECAST_URL = "https://api.openweathermap.org/data/2.5/forecast"
def get_5day_forecast(city):
params = {"q": city, "appid": API_KEY, "units": "metric"}
response = requests.get(BASE_FORECAST_URL, params=params)
if response.status_code == 200:
return response.json()
return {"error": "City not found!"}
The app now includes visual graphs to display:
import matplotlib.pyplot as plt
def plot_weather_trends(forecast_data):
dates = [item['dt_txt'] for item in forecast_data['list'][:5]]
temps = [item['main']['temp'] for item in forecast_data['list'][:5]]
plt.plot(dates, temps, marker='o', linestyle='-', color='b')
plt.xlabel('Date')
plt.ylabel('Temperature (ยฐC)')
plt.title('5-Day Temperature Trend')
plt.xticks(rotation=45)
plt.show()
To ensure the weather API integration works correctly, run:
python -m unittest discover tests

Feel free to fork this repository and submit pull requests to improve the project!
This project is designed to provide accurate and up-to-date weather information in a simple format. ๐๐ค Let us know if you have suggestions for improvements! ๐