0% found this document useful (0 votes)
26 views19 pages

Computer Pro

Uploaded by

lobrandi46
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views19 pages

Computer Pro

Uploaded by

lobrandi46
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

INTRODUCTION

OpenWeatherMap is a powerful weather data platform that


provides real-time and historical weather data through a
user-friendly API. It is widely used by developers,
researchers, and businesses for integrating accurate weather
information into their applications, websites, and systems.

The project aims to make weather data easily accessible and


customizable, supporting a wide range of use cases such as
forecasting, climate research, agriculture, travel planning, and
IoT systems. OpenWeatherMap offers data for current
weather conditions, short-term and long-term forecasts,
historical data, and even advanced features like air pollution
levels and UV indices.
CERTIFICATE

It Is Certified That Project Work and Report Titled


“Weather forecast app, using APIs.”
Submitted by BHADO MURMU of class XII-A, Roll No.10,
CBSE Roll No—
Studying in Atomic Energy Central School-I Jadugoda for The
Partial Fulfilment of The Requirement of AISSCE 2024-2025.
This Work Is Carried Under My Supervision.

PAWAN KUMAR. External Examiner


PGT, Computer department

N.K. BLAHATIA
Principal
ACKNOWLEDGEMENT

I selected this project as a part of my studies, titled


“Weather forecast app, using APIs”.
As gratitude, I convey my sincere thanks to our Computer
Teacher Shri PAWAN KUMAR as well as principal sir Shri.
N.K.BLAHATIA who were our constant guide,
during the period of study and without whose help it would
not have been possible for us to complete this project. Also I
wanted
to thank all my friends to help me in this project.

At last I wanted to thank all those who have helped me with


this
project.
APIs
An API (Application Programming Interface) is a mechanism
that allows different software applications to communicate
with each other. It defines the methods and data formats that
programs can use to request and exchange information.

General Overview of APIs

1. Purpose of APIs:
Simplify development by allowing developers to use existing
functionalities or data from other applications.
Allow integration between software systems, devices, or
services.

2.How APIs Work:


Request: An application sends a request to an API endpoint (a
URL or address).
Processing: The API processes the request on the server-side.
Response: The server sends back a response, usually in JSON
or XML format.
• Types of APIs:

Web APIs: Accessible via the internet (e.g., OpenWeatherMap,


Google Maps).

Library APIs: Used within programming languages (e.g.,


Python’s math library).

Operating System APIs: Expose system-level functionalities


(e.g., Windows APIs).

Hardware APIs: Interact with hardware devices (e.g., camera


or printer).

• API Example( used in this project)


Weather App: Fetch real-time weather data.
Request:

http://api.openweathermap.org/data/2.5/weather?q=London&
appid=YOUR_API_KEY
Response:
{ “weather”: [{“description”: “clear sky”}],
“main”: {“temp”: 15.5, “humidity”: 40},
“wind”: {“speed”: 2.1}
}

Key Features of APIs

1. Endpoints: URLs where requests are sent (e.g., /weather,


/forecast).

2.Authentication: Use API keys, tokens, or OAuth for security.

• Request Methods:
GET: Retrieve data (e.g., get weather for a city).
POST: Send data to the server (e.g., submit a form).
PUT: Update data.
DELETE: Remove data.
3.Rate Limits: Restrict the number of requests to prevent
overuse.

4.Versioning: APIs are often versioned (e.g., /v1/weather).

• Real-World Examples of APIs

1. Social Media APIs:


Fetch user data, posts, or analytics (e.g., Facebook, Twitter).

2.Payment APIs:
Process payments securely (e.g., PayPal, Stripe).

3.Mapping APIs:
Provide directions or maps (e.g., Google Maps API).

4.Machine Learning APIs:


Use pre-built AI models (e.g., OpenAI GPT, Google Vision API).
Advantages of APIs

1.Efficiency: Reuse existing functionalities instead of building


from scratch.

2.Interoperability: Enable communication between different


software platforms.

3.Scalability: APIs can handle large-scale data exchanges.

4.Automation: Automate workflows by connecting services.


Tinkter library

The tkinter library is Python’s standard GUI (Graphical User


Interface) package, allowing developers to create interactive
desktop applications. It is included with most Python
installations, making it widely accessible. tkinter is a wrapper
around the Tcl/Tk GUI toolkit.

• Key Features:

1.Widgets: Provides a variety of pre-built GUI elements, such


as:
Button: For clickable buttons.
Label: For displaying text or images.
Entry: For single-line text input.
Text: For multi-line text input.
Canvas: For drawing graphics.
Menu: For creating menus.
Frame: For grouping other widgets.

2.Event Handling: Supports event-driven programming, where


user actions like clicks, key presses, and others trigger events.

3.Cross-Platform: Works on Windows, macOS, and Linux.


4. Ease of Use: Simplifies GUI creation with Python’s object-
oriented approach.

• Example:

import tkinter as tk
# Create the main window
root = tk.Tk()
root.title("Hello Tkinter")
# Add a label widget
label = tk.Label(root, text="Welcome to Tkinter!")
label.pack() # Automatically place the widget
# Add a button to close the window
button = tk.Button(root, text="Close", command=root.quit)
button.pack()
# Run the application
root.mainloop()
• Components of tkinter:

Tk: The main application window.


Widgets: GUI components added to the application
window.Geometry Managers: Control the placement of
widgets (pack, grid, or place).

‘ttk (Themed Tkinter) provides modern, themed widgets.’


OpenWeatherMap

The OpenWeatherMap API is a popular weather service API


that provides real-time and historical weather data for
locations worldwide. It is widely used in applications to
retrieve weather-related information, such as temperature,
humidity, wind speed, and forecasts.

• Key Features of OpenWeatherMap API:


1.Current Weather Data:
Provides real-time weather information for any location.

2.Weather Forecast:
Hourly, daily, or 5-day/3-hour forecasts.

3.Historical Weather Data:


Accessing the past weather information for specific locations.

4.Air Pollution Data:


Retrieve data on air quality and pollutants like CO₂, PM2.5, etc.

5.Geocoding:
Convert city names or coordinates into geographic
information.
6.Weather Maps:
Visual maps with overlays for clouds, precipitation,
temperature, and wind.

• API Access:

To use the OpenWeatherMap API, we need to:

1.Sign Up: Create a free account on the OpenWeatherMap


website.

2.Generate API Key: Obtain an API key after signing up. This
key authenticates our requests.
Conclusion

In conclusion, OpenWeatherMap serves as a comprehensive


and reliable platform for accessing a wide range of weather
data. Its versatility, scalability, and ease of use make it an
essential tool for developers and organizations looking to
integrate weather insights into their solutions.

By providing real-time and historical weather information


along with advanced metrics, OpenWeatherMap empowers
users to make data-driven decisions across diverse fields such
as environmental monitoring, logistics, agriculture, and smart
city initiatives.

As the world increasingly relies on accurate weather data for


critical operations, OpenWeatherMap continues to play a
pivotal role in shaping the way we understand and interact
with weather systems.
Bibliography
• https://www.geeksforgeeks.org/
• https://home.openweathermap.org/
Code for weather app..

import tkinter as tk
from tkinter import messagebox
import requests

def get_weather():
city = city_entry.get()
if not city:
messagebox.showerror(“Error”, “Please
enter a city name”)
return

api_key = “f8c53154b1b91ca62c47c7eb1f2d8b5c” #
your OpenWeatherMap API key

try:
response = requests.get(url)
response.raise_for_status()
data = response.json()

# Extract weather data


City_name = data[“name”]
Temp = data[“main”][“temp”]
Weather_desc =
data[“weather”][0][“description”]
Humidity = data[“main”][“humidity”]
Wind_speed = data[“wind”][“speed”]
# Display weather info
Result_label.config(
Text=f”City: {city_name}\n”
F”Temperature: {temp}°C\n”
F”Weather:
{weather_desc.capitalize()}\n”
F”Humidity: {humidity}%\n”
F”Wind Speed: {wind_speed} m/s”
)
Except requests.exceptions.RequestException
as e:
Messagebox.showerror(“Error”, “Failed to
get weather data. Check your connection.”)
Except KeyError:
Messagebox.showerror(“Error”, “City not
found. Please check the city name.”)

# Create the main Tkinter window


Root = tk.Tk()
Root.title(“Weather App”)
Root.geometry(“400x400”)

# City entry field


City_label = tk.Label(root, text=”Enter City:”,
font=(“Arial”, 14))
City_label.pack(pady=10)

City_entry = tk.Entry(root, font=(“Arial”, 14),


width=20)
City_entry.pack(pady=5)
# Button to get weather
Get_weather_button = tk.Button(root, text=”Get
Weather”, font=(“Arial”, 14),
command=get_weather)
Get_weather_button.pack(pady=10)

# Label to display weather result


Result_label = tk.Label(root, text=””,
font=(“Arial”, 14), justify=”left”)
Result_label.pack(pady=20)

# Run the Tkinter event loop


Root.mainloop()

You might also like