0% found this document useful (0 votes)
9 views31 pages

OUTPUT671

The document outlines the structure and functionality of a weather application, including user authentication features like sign-up and login, and data retrieval from an external weather API. It details the technology stack, hardware and software requirements, and the main program pages for user input and output. Additionally, it includes code snippets for database connection, data handling, and user interface elements using Tkinter.

Uploaded by

copyvivek18
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)
9 views31 pages

OUTPUT671

The document outlines the structure and functionality of a weather application, including user authentication features like sign-up and login, and data retrieval from an external weather API. It details the technology stack, hardware and software requirements, and the main program pages for user input and output. Additionally, it includes code snippets for database connection, data handling, and user interface elements using Tkinter.

Uploaded by

copyvivek18
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/ 31

1

2
3
4
5
6
7
8
index
1. About

2. Objectives

3. Technology Stack

4. Hardware Requirements

5. Software Requirements

6. User Input Requirements

7. Features

8. Project Scope

9. Limitations

10. Main Program Pages (Input Pages)

11. Output Pages

12.Future Enhancements

13. Conclusion

14. References

9
Admin.py
import mysql.connector
from mysql.connector import Error
from tkinter import *
from tkinter import messagebox, ttk
import requests
import json

# Connect to MySQL

def connect_to_database():
try:
connection = mysql.connector.connect(
host='localhost',
user='vivek',
password='12345',
database='weather_app'
)
if connection.is_connected():
return connection
except Error as e:
messagebox.showerror("Database Error",
f"Error connecting to MySQL: {e}")
return None

10
# Function to handle sign-up
def sign_up():
username = username_entry.get()
password = password_entry.get()
confirm_password =
confirm_password_entry.get()

if not username or not password:


messagebox.showerror("Error", "All
fields are required!")
return
if password != confirm_password:
messagebox.showerror("Error", "Passwords
do not match!")
return

connection = connect_to_database()
if not connection:
return

try:
cursor = connection.cursor()
# Check if username already exists
cursor.execute("SELECT username FROM
users WHERE username = %s", (username,))
if cursor.fetchone():
messagebox.showerror("Error",
"Username already exists!")
return
# Insert new user into database
cursor.execute("INSERT INTO users
(username, password) VALUES (%s, %s)",
(username, password))
connection.commit()
messagebox.showinfo("Success", "Sign-Up
Successful!")
sign_up_window.destroy()
show_login_page()
except Error as e:
messagebox.showerror("Database Error",
f"Error during sign-up: {e}")
finally:
connection.close()

11
# Function to handle login

def login():
username = username_entry.get()
password = password_entry.get()
connection = connect_to_database()
if not connection:
return

try:
cursor = connection.cursor()

# Validate user credentials

cursor.execute("SELECT password FROM users


WHERE username = %s", (username,))
result = cursor.fetchone()
if result and result[0] == password:
messagebox.showinfo("Success", "Login
Successful!")
login_window.destroy()
open_weather_app()
else:
messagebox.showerror("Error", "Invalid
username or password!")
except Error as e:
messagebox.showerror("Database Error",
f"Error during login: {e}")
finally:
connection.close()

12
# Function to open the Login page

def show_login_page():
global login_window, username_entry,
password_entry
login_window = Tk()
login_window.title("Login")
login_window.geometry("400x400")
Label(login_window, text="Login",
font=("Arial", 24, "bold")).pack(pady=20)
Label(login_window, text="Username",
font=("Arial", 14)).pack(pady=5)
username_entry = Entry(login_window,
font=("Arial", 14))
username_entry.pack(pady=5)
Label(login_window, text="Password",
font=("Arial", 14)).pack(pady=5)
password_entry = Entry(login_window,
font=("Arial", 14), show="*")
password_entry.pack(pady=5)
Button(login_window, text="Login",
font=("Arial", 14), command=login).pack(pady=20)
Button(login_window, text="Sign Up",
font=("Arial", 14),
command=show_sign_up_page).pack(pady=5)
login_window.mainloop()

13
# Function to open the Sign-Up page

def show_sign_up_page():
global sign_up_window, username_entry,
password_entry, confirm_password_entry
login_window.destroy()
sign_up_window = Tk()
sign_up_window.title("Sign-Up")
sign_up_window.geometry("400x400")
Label(sign_up_window, text="Sign-Up",
font=("Arial", 24, "bold")).pack(pady=20)
Label(sign_up_window, text="Username",
font=("Arial", 14)).pack(pady=5)
username_entry = Entry(sign_up_window,
font=("Arial", 14))
username_entry.pack(pady=5)
Label(sign_up_window, text="Password",
font=("Arial", 14)).pack(pady=5)
password_entry = Entry(sign_up_window,
font=("Arial", 14), show="*")
password_entry.pack(pady=5)
Label(sign_up_window, text="Confirm Password",
font=("Arial", 14)).pack(pady=5)
confirm_password_entry = Entry(sign_up_window,
font=("Arial", 14), show="*")
confirm_password_entry.pack(pady=5)
Button(sign_up_window, text="Sign Up",
font=("Arial", 14), command=sign_up).pack(pady=20)
sign_up_window.mainloop()

14
Main.py
# Weather App Functions

def data_get():
city = city_name.get()
data = requests.get(
f"https://api.openweathermap.org/data/2.5/wea
ther?q={city}&appid=a4cf8acf9c4e4a5be39d9575b2097297"
).json()
if data.get("cod") != 200:
w_label1.config(text="Invalid City")
wb_label1.config(text="")
temp_label1.config(text="")
per_label1.config(text="")
humidity_label1.config(text="")
wind_label1.config(text="")
visibility_label1.config(text="")
return

w_label1.config(text=data["weather"][0]["main"])
wb_label1.config(text=data["weather"][0]["descrip
tion"])
temp_label1.config(text=str(int(data["main"]["tem
p"] - 273.15)) + "°C")
per_label1.config(text=str(data["main"]["pressure
"]) + " hPa")
humidity_label1.config(text=str(data["main"]["hum
idity"]) + " %")
wind_label1.config(text=str(data["wind"]["speed"]
) + " m/s")
visibility_label1.config(text=str(data["visibilit
y"] // 1000) + " km")

15
def save_data():
city = city_name.get()
weather = w_label1.cget("text")
description = wb_label1.cget("text")
temperature = temp_label1.cget("text")
pressure = per_label1.cget("text")
humidity = humidity_label1.cget("text")
wind_speed = wind_label1.cget("text")
visibility = visibility_label1.cget("text")
connection = connect_to_database()
if not connection:
return
try:
cursor = connection.cursor()
# Insert weather data into the database
cursor.execute(
"INSERT INTO weather_data (city_name,
weather, description, temperature, pressure,
humidity, wind_speed, visibility) "
"VALUES (%s, %s, %s, %s, %s, %s, %s,
%s)",
(city, weather, description,
temperature, pressure, humidity, wind_speed,
visibility)
)
connection.commit()
messagebox.showinfo("Success", "Weather data
saved to database!")
except Error as e:
messagebox.showerror("Database Error",
f"Error saving weather data: {e}")
finally:
connection.close()
# Start the login page
show_login_page()
def open_weather_app():
global city_name, w_label1, wb_label1,
temp_label1, per_label1, humidity_label1,
wind_label1, visibility_label1

win = Tk()
win.title("AeroMeter")
win.geometry("1408x704")

16
# Function to open the weather
application

from tkinter import *


from tkinter import ttk
import requests
import json

def data_get():
city = city_name.get()
data = requests.get(
f"https://api.openweathermap.org/data/2.5/wea
ther?q={city}&appid=a4cf8acf9c4e4a5be39d9575b2097297"
).json()
if data.get("cod") != 200:
w_label1.config(text="Invalid City")
wb_label1.config(text="")
temp_label1.config(text="")
per_label1.config(text="")
humidity_label1.config(text="")
wind_label1.config(text="")
visibility_label1.config(text="")
return
w_label1.config(text=data["weather"][0]["main"])
wb_label1.config(text=data["weather"][0]["descrip
tion"])
temp_label1.config(text=str(int(data["main"]["tem
p"] - 273.15)) + "°C")
per_label1.config(text=str(data["main"]["pressure
"]) + " hPa")
humidity_label1.config(text=str(data["main"]["hum
idity"]) + " %")
wind_label1.config(text=str(data["wind"]["speed"]
) + " m/s")
visibility_label1.config(text=str(data["visibilit
y"] // 1000) + " km")

17
def clear_fields():
city_name.set("")
w_label1.config(text="")
wb_label1.config(text="")
temp_label1.config(text="")
per_label1.config(text="")
humidity_label1.config(text="")
wind_label1.config(text="")
visibility_label1.config(text="")

def save_data():
data = {
"city": city_name.get(),
"weather": w_label1.cget("text"),
"description": wb_label1.cget("text"),
"temperature": temp_label1.cget("text"),
"pressure": per_label1.cget("text"),
"humidity": humidity_label1.cget("text"),
"wind_speed": wind_label1.cget("text"),
"visibility": visibility_label1.cget("text")
}
with open("weather_data.txt", "w") as file:
file.write(json.dumps(data))

def load_data():
try:
with open("weather_data.txt", "r") as file:
data = json.load(file)
city_name.set(data["city"])
w_label1.config(text=data["weather"])
wb_label1.config(text=data["description"])
temp_label1.config(text=data["temperature"])
per_label1.config(text=data["pressure"])
humidity_label1.config(text=data["humidity"]
)
wind_label1.config(text=data["wind_speed"])
visibility_label1.config(text=data["visibili
ty"])
except FileNotFoundError:
print("No saved data found.")

18
def refresh_data():
data_get()

win = Tk()
win.title("AeroMeter")
win.geometry("1408x704")
# Adding Background Image:
bg_image =
PhotoImage(file="D:\\pythonproject101\\projectpython
23\\img.png")
bg_label = Label(win, image=bg_image)
bg_label.place(relwidth=1, relheight=1)
name_label = Label(win, text="AeroMeter",
font=("Times New Roman", 28, "bold"),
bg="lightblue")
name_label.place(x=25, y=50, height=50, width=450)
city_name = StringVar()
List_name = [
"Andhra Pradesh", "Arunachal Pradesh", "Assam",
"Bihar", "Chhattisgarh", "Goa", "Gujarat",
"Haryana", "Himachal Pradesh", "Jammu and
Kashmir", "Jharkhand", "Karnataka", "Kerala",
"Madhya Pradesh", "Maharashtra", "Manipur",
"Meghalaya", "Mizoram", "Nagaland", "Odisha",
"Punjab", "Rajasthan", "Sikkim", "Tamil Nadu",
"Telangana", "Tripura", "Uttar Pradesh",
"Uttarakhand", "West Bengal", "Andaman and
Nicobar Islands", "Chandigarh", "Dadra and Nagar
Haveli",
"Daman and Diu", "Lakshadweep", "National
Capital Territory of Delhi", "Puducherry"
]
com = ttk.Combobox(win, values=List_name,
font=("Times New Roman", 20, "bold"),
textvariable=city_name)
com.place(x=25, y=120, height=50, width=450)
w_label = Label(win, text="Weather Climate",
font=("Times New Roman", 20), bg="lightblue")
w_label.place(x=25, y=260, height=50, width=210)

19
w_label1 = Label(win, text="", font=("Times New
Roman", 20), bg="lightblue")
w_label1.place(x=250, y=260, height=50, width=210)

wb_label = Label(win, text="Weather Description",


font=("Times New Roman", 17), bg="lightblue")
wb_label.place(x=25, y=320, height=50, width=210)
wb_label1 = Label(win, text="", font=("Times New
Roman", 17), bg="lightblue")
wb_label1.place(x=250, y=320, height=50, width=210)
temp_label = Label(win, text="Temperature",
font=("Times New Roman", 20), bg="lightblue")
temp_label.place(x=25, y=380, height=50, width=210)
temp_label1 = Label(win, text="", font=("Times New
Roman", 20), bg="lightblue")
temp_label1.place(x=250, y=380, height=50,
width=210)
per_label = Label(win, text="Pressure", font=("Times
New Roman", 20), bg="lightblue")
per_label.place(x=25, y=440, height=50, width=210)
per_label1 = Label(win, text="", font=("Times New
Roman", 20), bg="lightblue")
per_label1.place(x=250, y=440, height=50, width=210)
humidity_label = Label(win, text="Humidity",
font=("Times New Roman", 20), bg="lightblue")
humidity_label.place(x=25, y=500, height=50,
width=210)
humidity_label1 = Label(win, text="", font=("Times
New Roman", 20), bg="lightblue")
humidity_label1.place(x=250, y=500, height=50,
width=210)
wind_label = Label(win, text="Wind Speed",
font=("Times New Roman", 20), bg="lightblue")
wind_label.place(x=25, y=560, height=50, width=210)
wind_label1 = Label(win, text="", font=("Times New
Roman", 20), bg="lightblue")
wind_label1.place(x=250, y=560, height=50,
width=210)

20
visibility_label = Label(win, text="Visibility",
font=("Times New Roman", 20), bg="lightblue")
visibility_label.place(x=25, y=620, height=50,
width=210)
visibility_label1 = Label(win, text="", font=("Times
New Roman", 20), bg="lightblue")
visibility_label1.place(x=250, y=620, height=50,
width=210)
done_button = Button(win, text="Done", font=("Times New
Roman", 20, "bold"), command=data_get)
done_button.place(y=190, h=50, width=100, x=40)

clear_button = Button(win, text="Clear", font=("Times


New Roman", 20, "bold"), command=clear_fields)
clear_button.place(y=190, h=50, width=100, x=160)
save_button = Button(win, text="Save Data",
font=("Times New Roman", 20, "bold"),
command=save_data)
save_button.place(y=90, h=50, width=140, x=1220)

load_button = Button(win, text="Load Data",


font=("Times New Roman", 20, "bold"),
command=load_data)
load_button.place(y=90, h=50, width=150, x=1060)
refresh_button = Button(win, text="Refresh",
font=("Times New Roman", 20, "bold"),
command=refresh_data)
refresh_button.place(y=190, h=50, width=150, x=280)
win.mainloop()

21
Mysql code :

| City | Weather | Description | Temperature | Pressure | Humidity | Wind Speed | Visibility |


---------------------------------------------------------------------------------------------------------
| New York | Clear | clear sky | 25°C | 1012 hPa | 45 % | 5 m/s | 10 km |
| Los Angeles | Rain | light rain | 18°C | 1008 hPa | 80 % | 2 m/s | 6 km |
...

22
23
LOGIN PAGE

24
SIGN-UP PAGE

25
Interface

•Project Name (Title):


•"AeroMeter" is prominently displayed as the title of your application.

•Search or Input Field:


•A dropdown or text field is provided for the user to input or select a city or
location.

•Action Buttons:
•Done: Likely confirms the city selection or fetches data based on the input.
•Clear: Resets or clears the input field and any displayed data.
•Refresh: Refreshes the data, perhaps fetching updated weather information

26
Weather Display

•Weather Data Display:

•Labels: Space is dedicated to displaying various weather attributes,


including:
•Weather Climate
•Weather Description
•Temperature
•Pressure
•Humidity
•Wind Speed
•Visibility

27
Steps to Use the
Weather App
•Enter Location: Type the name
of a state or city (e.g.,
"Uttarakhand") in the input
field.

•Action Buttons:
•Click "Done" to fetch weather
data.
•Use "Clear" to reset the input
field.
•Click "Refresh" to update the
weather information.

•Weather Details: The app


retrieves and displays data like:
•Weather Climate (e.g., Clouds)
•Description (e.g., Broken
clouds)
•Temperature, Pressure,
Humidity, Wind Speed, and
Visibility.

•Output Display: The fetched


weather details are shown in
their respective sections for
easy understanding.

28
Error while typing city
name

Error Handling: Displays "Invalid


City" for incorrect inputs, improving
usability.

Guidance: Alerts the user to


check and correct their input,
avoiding confusion.

29
Save Button:
•Purpose: Saves the displayed weather data into a MySQL database for future use.

Load Button:
•Purpose: Retrieves and displays saved weather data from the MySQL database.

30
Comparing accuracy of
data :
• Update Timing: Differences
arise due to varying update
intervals between the app
and the website.

• Data Sources: The app and


the site may use different
weather APIs or models.

• Location Accuracy: Small


variations in location data
(latitude/longitude) can
affect results.

• Data Estimation:
Interpolation methods by
different services can cause
discrepancies.

• Calculations: Differences
in rounding, unit
conversions, or formulas
can impact values.

• Real-Time vs Forecast:
One source might show
real-time data, while the
other shows forecasts.

• API Variations: API-


specific behaviors or
regional data processing
can lead to mismatches.

31

You might also like