Project (Weather Forecast) CSE-A

Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

- A PROJECT REPORT ON –

“WEATHER FORECAST”
(FETCHING WEATHER)

MINI PROJECT IN “COMPUTER SCIENCE AND ENGINEERING”


Submitted by:
• B. SANGEETHA ROLLNO - 22BH1A0522
• D. DURGA DEVI ROLLNO - 22BH1A0557
• G. LAKSHMI ROLLNO - 22BH1A0581
• G. NAGESHWARI ROLLNO - 22BH1A0584
• K. SINDHUJA ROLLNO - 22BH1A05A2

ST. MARY’S ENGINEERING COLLEGE


(Approved by AICT,NEW DELHI,& Affiliated to JNTU-HYDERABAD)

Deshmukhi (V),Pochampally(M), Yadadri- Bhuvanagiri (D), Telangana -508248

2024-2025
CERTIFICATE

This is to certify that, the Presentation entitled “WEATHER FORECAST” is


submitted by B. Sangeetha (22BH1A0522), D. Durga Devi (22BH1A0557),
G. Lakshmi (22BH1A0581), G. Nageshwari (22BH1A0584), K. Sindhuja
(22BH1A05A2) B. Tech Computer Science and Engineering, In Partial
fulfilment. For the requirement of the presentation and for the award of the
Degree of Bachelor of Technology during the academic year 2024-2025.
ACKNOWLEDGEMENTS

We would like to thank our HOD Dr M. MALLA REDDY Principal Dr T.N


SRINIVAS RAO of St Marys College for giving an opportunity of making this
mini project. We own our sincere gratitude towards St. Mary’s engineering
college.
Our heartfelt thanks to Dr Malla Reddy sir for guiding us on this project. We
are deeply indebted to our Srinivas sir for helping us to complete this
project. We further thank to all the staff members of St Marys engineering
college-hyd. We also express our deepest gratitude to our parents. Finally,
we would like to wind up by paying our heartfelt thanks to all our near and
dear ones.

• B. SANGEETHA 22BH1A0522
• D. DURGA DEVI 22BH1A0557
• G. LAKSHMI 22BH1A0581
• G. NAGESHWARI 22BH1A0584
• K. SINDHUJA 22BH1A05A2
INDEX

• ABSTRACT OF THE PROJECT


• INTRODUCTION OF THE PROJECT
• PROBLEM STATEMENT
• SYSTEM REQUIREMENTS
• SOURCE CODE AND IMPLEMENTATION
• OUTPUT OF THE PROJECT
• CONCLUSION OF THE PROJECT
ABSTRACT

Weather forecasting is the application of science and technology to predict


the state of the atmosphere for a given location. Ancient weather
forecasting methods usually relied on observed patterns of events, also
termed pattern recognition. For example, it might be observed that if the
sunset was particularly red, the following day often brought fair weather.
However, not all of these predictions prove reliable. Here this system will
predict weather based on parameters such as temperature, humidity and
wind. User will enter current temperature; humidity and wind, System will
take this parameter and will predict weather (rainfall in inches) from
previous data in database (dataset). The role of the admin is to add
previous weather data in database, so that system will calculate weather
(estimated rainfall in inches) based on these data. Weather forecasting
system takes parameters such as temperature, humidity, and wind and will
forecast weather based on previous record therefore this prediction will
prove reliable. This system can be used in Air Traffic, Marine, Agriculture,
Forestry, Military, and Navy etc.
IMPORTANCE OF USING A WEATHER
FORECAST:

Weather forecasts have several important uses across various sectors and
for individual planning. Some key uses include:

• Planning Outdoor Activities: Individuals and organizations use


forecasts to plan outdoor events, sports activities, and recreational
outings based on expected weather conditions.

• Aviation and Transportation: Airlines, pilots, and airports rely on


forecasts to anticipate weather patterns that could affect flight
paths, turbulence, and airport operations.

• Agriculture and Farming: Farmers use forecasts to plan planting,


irrigation, and harvesting schedules, as well as to protect crops from
adverse weather conditions like frost or heavy rain.

• Construction and Infrastructure: Builders and contractors


schedule construction activities based on weather forecasts to
ensure worker safety and project timelines.

• Energy Sector: Energy companies utilize forecasts to manage


energy demand, plan for renewable energy generation, and prepare
for weather-related disruptions.

• Emergency Response and Public Safety: Emergency services use


forecasts to prepare for and respond to natural disasters such as
hurricanes, floods, and wildfires.
• Tourism and Hospitality: Tourist destinations and hotels use
forecasts to manage bookings and activities, ensuring a positive
experience for visitors.

• Health and Well-being: Individuals with health conditions affected


by weather, such as asthma or allergies, use forecasts to prepare
accordingly.

• Environmental Monitoring: Scientists and researchers use weather


forecasts to study climate patterns, monitor environmental changes,
and predict the impact of weather on ecosystems.

Overall, accurate weather forecasts play a crucial role in improving


efficiency, safety, and decision-making across various sectors of society.
PROBLEM STATEMENT

The problem statement for weather forecasting typically involves predicting


future atmospheric conditions based on historical data and current
observations. This prediction aims to provide accurate information about
temperature, precipitation, wind speed, humidity, and other relevant
parameters over a specific period in a given geographical area. The
challenge lies in utilizing complex models, algorithms, and data analytics
to make these predictions as precise and reliable as possible, considering
the inherent uncertainties and dynamic nature of weather systems.

SYSTEM REQUIREMENTS

To run this weather forecast application using Python and Tkinter, we need
a system that meets the following requirements:

• Hardware Requirements

➢ Processor: Modern multi-core processor (Intel i5/i7 or AMD


equivalent)
➢ RAM: At least 4 GB (8 GB or more recommended for better
performance)
➢ Storage: 100 MB free space (more if handling large data or logs)
➢ Internet Connection: Required to fetch data from the
OpenWeatherMap API

• Software Requirements

➢ Operating System
- Windows 10/11, macOS, or a modern Linux distribution (Ubuntu,
Fedora, etc.)

➢ Python Environment
-Python Version: Python 3.7 or higher

• Python Libraries
➢ requests: For making HTTP requests to the weather API.

Pip install request

➢ Pillow: For handling image processing.

pip install pillow

• Additional Software
➢ Tkinter: Tkinter is included with standard Python installations. No
additional installation is typically needed for Tkinter.

• Setting Up the Environment


1. Install Python: Ensure Python 3.7 or higher is installed on your system.
You can download it from the official [Python
website](https://www.python.org/downloads/).
2. Create Virtual Environment (optional but recommended):
Python -m venv venv
Source venv/bin/activate #on Windows use `venv\Scripts\activate
3. Install Required Libraries:
pip install requests pillow

• Project Structure
Here's a simple project structure to organize the files:
Weather _forecast/

├── main.py # Main script for the weather forecast application
├── README.md # Project documentation
└── requirements.txt # List of dependencies
➢ requirements.txt Content
Create a requirements.txt file with the following content to easily install
dependencies:

requests
pillow

• Running the Application


To run the application, navigate to the directory containing main.py and
execute:

python main.py

• Install the required libraries:


pip install -r requirements.txt

• Usage
1. Replace the `api_key` in the `main.py` file with your actual
OpenWeatherMap API key.
2. Run the application:

python main.py

• License
This project is licensed under the MIT License.

By following these steps and ensuring your system meets the


requirements, you will be able to run the weather forecast application
smoothly
SOURCE CODE AND IMPLEMENTATION:

SOURCE CODE:
EXPLANATION:
Importing Necessary Libraries

• ‘tkinter`: This module is used to create the GUI.


• ‘messagebox`: This submodule of tkinter is used to show error
message.
• ‘PIL (Pillow)`: This is used for handling images, including
opening and displaying images.
• ‘requests`: This module is used to make HTTP requests.
• ‘io`: This module is used to handle binary data streams, such
as image data.

Defining the get_weather Function

• This function takes a city name as input.


• It constructs a request to. the OpenWeatherMap API using the
provided city and api_key.
• It handles various potential exceptions (HTTP errors, connection
errors, timeouts, and other request exceptions).
• If the request is successful, it returns the weather data in JSON
format. If not, it returns None.

Defining the show_weather Function

• This function retrieves the city name from the entry widget.
• It calls get_weather to get the weather data.
• If data is available, it extracts temperature, description, humidity,
wind speed, and icon code from the JSON response.
• It sets these details into the result StringVar.
• It also fetches the weather icon and displays it in the icon_label.
• If no data is found or the city name is empty, it displays an error
message.
Creating the Main Application Window

• Initializes the main application window.


• Sets the title, size, and background color.

Adding the Header

• Creates a label widget for the header with the specified font and
background color.
• Adds padding around the header for better visual appearance.

Creating the Input Frame

• Creates a frame to hold the city label, entry widget, and button.
• Adds the label, entry widget, and button with appropriate styling and
padding.

Creating the Result Frame

• Creates a frame for displaying the weather results.


• Uses a StringVar to hold the result text.
• Adds a label to display the result text.

Adding the Icon Label

• Adds a label widget for displaying the weather icon.

Starting the Application Loop

• Starts the Tkinter event loop to run the application.


OUTPUT

The graphical user interface (GUI) application for fetching and displaying
weather information. Here’s a step-by-step description of what the
application looks like and how it behaves:

Application Window
• Title: The window title is "Weather Forecast".
• Size: The window size is set to 400x400 pixels.
• Background Color: The background color of the window is light gray
(#d9d9d9).

Header
• Label: A header label at the top of the window displays "Weather
Forecast" in a bold, large font.
• Padding: The header has padding to ensure it is visually separated
from other elements.

Input Frame
• City Label: A label prompting the user to enter the city name.
• City Entry: An entry widget where the user types the name of the city.
• Fetch Button: A button labeled "Fetch Weather" which the user clicks
to retrieve the weather information for the entered city.
Result Frame
• Result Label: A label that displays the weather information fetched
from the API. This includes:
➢ Temperature in degrees Celsius.
➢ Weather description (e.g., "clear sky").
➢ Humidity percentage.
➢ Wind speed in meters per second.
• Icon Label: A label to display the weather icon associated with the
current weather conditions.
Behavior
• Initial State: The application starts with empty input fields and no
weather information displayed.
• Fetching Weather:
➢ The user types the city name in the entry widget.
➢ The user clicks the "Fetch Weather" button.
➢ The application calls the get_weather function to retrieve weather
data from the OpenWeatherMap API.

• Displaying Weather:
➢ If the city name is valid and weather data is retrieved, the
application updates the result label with temperature, description,
humidity, and wind speed.
➢ The weather icon is fetched from the OpenWeatherMap API and
displayed in the icon_label.
• Error Handling:
➢ If the city name is invalid or empty, an error message is displayed.
➢ If the weather data is not found for the entered city, an appropriate
message is displayed in the result label, and the icon is cleared.
CONCLUSION

The weather forecast project using Python and Tkinter successfully


demonstrates the integration of real-time weather data into a user-friendly
graphical interface. Through the use of APIs to fetch weather information,
and Tkinter for displaying this data, the application provides users with an
accessible tool to check current and upcoming weather conditions.

Key achievements of this project include:

• API Integration: Successfully fetched real-time weather data from a


reliable weather API.
• Graphical User Interface: Created a user-friendly interface using Tkinter,
allowing users to input their location and receive weather updates
seamlessly.
• Data Presentation: Displayed weather information clearly, including
temperature, humidity, wind speed, and weather descriptions, making it
easy for users to understand current conditions.

This project not only highlights the practical applications of Python in real-
world scenarios but also underscores the importance of combining various
libraries and tools to create comprehensive applications. Future
enhancements could include additional features like hourly forecasts,
weather alerts, and customizable themes to further improve user
experience.

Overall, the project serves as a solid foundation for developing more


advanced weather-related applications and showcases the versatility of
Python and Tkinter in building interactive and functional software
solutions.
THANKING YOU

You might also like