My Weather App

A Python-based app that fetches real-time weather data using the OpenWeatherMap API.

View the Project on GitHub nagakirankasi/my-weather-app

๐ŸŒฆ Real-Time Weather App

A Python-based app that fetches real-time weather data using the OpenWeatherMap API.

๐Ÿš€ Features


๐Ÿ“ฆ Installation

1๏ธโƒฃ Clone the Repository

git clone https://github.com/nagakirankasi/Weather-App.git
cd Weather-App

2๏ธโƒฃ Install Dependencies

Ensure Python 3.8+ is installed, then run:

pip install -r requirements.txt

Example requirements.txt:

requests
streamlit
flask
matplotlib

๐Ÿ”‘ API Setup

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"

๐ŸŒ Usage

1๏ธโƒฃ CLI Mode

Run the script in command line mode:

python weather.py

Enter the city name when prompted, and the weather details will be displayed.

2๏ธโƒฃ Web UI (Streamlit)

Launch the web interface:

streamlit run app.py

Use the input field to enter a city name and fetch weather data.


๐ŸŒค 5-Day Weather Forecast

The app now fetches and displays a 5-day weather forecast, including:

Example API Call for Forecast Data

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:

Example Graph Using Matplotlib

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()

๐Ÿงช Running Tests

To ensure the weather API integration works correctly, run:

python -m unittest discover tests

Short Demo

demo


๐Ÿ“ข Contributing

Feel free to fork this repository and submit pull requests to improve the project!

๐Ÿ”ฅ Future Enhancements


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! ๐Ÿš€