OUTPUT671
OUTPUT671
2
3
4
5
6
7
8
index
1. About
2. Objectives
3. Technology Stack
4. Hardware Requirements
5. Software Requirements
7. Features
8. Project Scope
9. Limitations
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()
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()
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
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)
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)
21
Mysql code :
22
23
LOGIN PAGE
24
SIGN-UP PAGE
25
Interface
•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
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.
28
Error while typing city
name
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 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.
31