Project Sample
Project Sample
1 PYTHON 2
2 PROJECT DESCRIPTION 4
3 FUNCTIONS USED 7
4 SOURCE CODE 9
5 SAMPLE OUTPUTS 13
6 CONCLUSION 15
7 BIBLIOGRAPHY 16
1
OVERVIEW OF PYTHON
WHAT IS PYTHON?
Python is a high-level, general-purpose programming language
known for its simplicity and readability. It was created by Guido
van Rossum and first released in 1991. Python has gained
widespread popularity in various fields, including web
development, data science, machine learning, scientific
computing, automation, and more. Here's an overview of Python's
key features and characteristics
BENEFITS OF PYTHON
• Readability: Python's syntax emphasizes readability and
clean code, making it easier for developers to write and
maintain code. It uses indentation (whitespace) to define
code blocks instead of curly braces or keywords, which
makes the code more human-friendly.
2
USES OF PYTHON IN REAL WORLD
WEB DEVELOPMENT:
Famously known as the go-to programming language for web
development, Python has an important role to play in it.
Python comes with multiple web
development frameworks like Pyramid, Django, and Flask.
These frameworks are packed with
standard libraries that allow easy protocol integration
DATA SCIENCE :
We all know that data science is one of the most in-
demand skills in the
market. Knowledge of data science is a sought-after skill in IT,
manufacturing, or eCommerce.
This is where Python steps in. Its multiple libraries, such as
Pandas, TensorFlow, NumPy, etc help
in extracting valuable information from the data.
SOFTWARE DEVELOPMENT:
One of the prime uses of Python is that it is used by
software
developers. Python simplifies the software development
process for complex apps. It is used for
project management, as a support programming language, to
build control, and testing .
3
WEATHER FORECAST USING PYTHON
Weather is one of the most crucial aspects of our life. It dictates
the different kinds of activities that we would like to plan
throughout the day, week, or month. One of the older methods of
reading weather patterns is to look at the sky and predict whether
it would stay sunny, rain, or have a humid weather condition. This
method might not be the most effective if you are not well versed
with climatic conditions and always end up getting your
predictions wrong. The other method includes waiting and
watching news channels for their daily reports to analyze the
weather. However, these ways seem a bit outdated for the modern
era we live in today.
There are different devices and tools that will allow you to
interpret the current weather conditions from satellite reports.
Python has got it all covered and using Python we can make a
weather forecast app. We will make use of such API technologies
with Python to create our own weather reporting application .
We will utilize Python and a weather reporting service that
provides us with an API key to interpret the daily weather
conditions of any particular place. One of the few library
requirements that we will need for the app to function is the
Tkinter and PIL module that is available in Python.
An API key from a website that stores information about the
weather and forecasts them with accurate results is required. Then
the app will result in favourable outputs based on different cities
weather reports
4
ThE OpENWEAThEr ApI
It a popular and widely used API that provides access to weather
data for various locations around the world. It offers a wide range
of weather-related information, including current weather
conditions, forecasts, historical weather data, and more.
To use the OpenWeather API, you need to sign up for an API key on
the OpenWeatherMap website, which you include in your API
requests to authenticate and access the data. The API offers both
free and paid plans, with varying levels of access, including higher
request limits and additional features for paid plans.
6
pYThON MODULES USED
In order for us to have our application up and running, we will
need to make use of some Python libraries, modules and
interpreters that will make it easier to develop the application by
adding some functionalities and interactivity to our application.
They include:
* TkINTEr :
Used to create a GUI interface for our application.
* pIL :
Python Pillow module is built on top of PIL (Python Image Library).
It is the essential modules for image processing in Python. It
supports the variability of images such as jpeg, png, bmp, gif.We
can do anything on the digital images using the pillow module such
as filtering images, Creating thumbnail, merging images, cropping
images.
* ApI :
An API, or Application Programming Interface, is a server that you
can use to retrieve and send data to using code. APIs are most
commonly used to retrieve data, and that will be the focus of this
beginner tutorial. When we want to receive data from an API, we
need to make a request. Requests are used all over the web.
* DICTIONArY :
A dictionary is a kind of data structure that stores items in key-
value pairs. A key
is a unique identifier for an item, and a value is the data associated
with that key. Dictionaries
7
often store information such as words and definitions, but they can
be used for much more.
Dictionaries are mutable in Python, which means they can be
changed after they are created.
* JSON :
Python JSON JavaScript Object Notation is a format for structuring
data. It is mainly
used for storing and transferring data between the browser and the
server. Python too supports
JSON with a built-in package called JSON.
8
SOURCE CODE
import tkinter as tk
import requests
from PIL import Image, ImageTk #pip install pillow
root-tk.Tk()
root.title("Weather App")
root.geometry("600x500")
#Key:0fecc68658de6ebc1257a7338a307885b
#Api url: api.openweathermap.org/data/2.5/weather?q={city
name}&appid={API key}
def format_responses(weather):
try:
city=weather[‘name’]
condition=weather[‘weather’][0][‘description’
temp=weather[‘main’][‘temp’])
final_str=’City:%s’\nCondition:%s\nTemprature:%s’%(city,conditio
n,temp)
except:
9
final_str=’There was an error while retrieving the
information’
return final_str
final_str=’City:%s’\nCondition:%s\nTemprature:%s’%(city,conditio
n,temp)
def get_weather(city):
weather_key=’ 0fecc68658de6ebc1257a7338a307885b’
url=’ https://api.openweathermap.org/data/2.5/weather’
params={‘APPID’:, weather_key,’q’:city,’units’:imperial’}
response=requests.get(url,params)
# print(response.jason())
weather=response.jason()
# print(temp=weather[‘main’][‘temp’]) [‘name’])
# print(weather[‘weather’][0][‘description’])
# print(weather[‘main’][‘temp’])
result[‘text’]=format_response(weather)
icon_name=weather[‘weather’][0][‘icon’]
open_image(icon_name)
defy open_image(icon_name):
size=int(frame_two.winfo_height()*0.25)
10
image=ImageTk.PhotoImage(Image.open(‘./img/’+icon+’.pmg’).re
size((size,size)))
weather_icon.delete(‘all’)
weather_icon.create_image(0,0,anchor=’nw’,image=img)
weather_icon.image=img
ing=Image.open('./bg.png')
ing=ing.resize((608,500), Image.ANTIALIAS)
ing_phot=-ImageTk. PhotoImage(img)
bg lbl=tk.Label(root, image=ing_photo)
bg_lbl.place(x=0,y=0,width=600,height=500)
txt_box=tk.Entry(frame_one,font”times new
roman”,25),width=17)
txt_box.grid(row+0,column=0,sticky’w’)
11
btn=tk.Button(frame_one,text=’GET WEATHER’,FG=’GREEN’,
font”times new
roman”,16,’bold’),command=lambda:get_weather(txt_box.get()))
btn.grid(row=0,column=1,padx=10)
frame_two=tk.Frame (bg_1b1, bg="#42c2f4", bd=5)
frame_two.place(x=80,y=130, width=450,height=300)
result=tk.lable(frame_two,font=40,bg=’white’,justify=’left’,anchor
=’nw’))
result.place(relwidth=1,realheight=1)
weather_icon=tk.Canvas(result,bg=’whitr’,bd=0,higlightthikness=0
)
weather_icon.place(xrel=.75,rely=0,relwidth=1,relhiegth=0.5)
root.mainloop()
12
SAMPLE OUTPUT
13
14
CONCLUSION
This project demonstrates the creation of a Weather Forecast
Application that provides the user with the accurate
information of the whether anywhere during anytime. This
application will allow us to know the atmospheric conditions
for a given location. We have tried to maxamize the
efficiency and made it easy for the staffs as well as the
students to access it. With the help of Python we have made
it as ideal as possible.
15
BIBLOGRAPHY
• https://youtu.be/FeR0wnXlp9c?si=-Zi0cp5wW_EuDwJU
• https://chat.openai.com/c/10fa0188-fb03-4367-8ccb-
8c5896840209
• https://www.geeksforgeeks.org/how-to-install-pil-on-
windows/
• https://www.google.com/search?q=how+does+openweather
map+work&sca_esv=571739304&rlz=1C1VDKB_enIN1060I
N1060&tbm=isch&sxsrf=AM9HkKnWtz6ci7nbg4M1SHNssE
W7AfR8tw:1696782666231&source=lnms&sa=X&ved=2ahU
KEwi1p9OA8OaBAxXe3jgGHSVYDGAQ_AUoAnoECAIQBA&bi
w=1536&bih=707&dpr=1.25#imgrc=2_akgKAG_OMikM
16