0% found this document useful (0 votes)
8 views23 pages

Yosup 21

The document outlines the implementation of a weather application named 'AeroMeter' using Python, MySQL, and Tkinter for the user interface. It includes functionalities for user sign-up and login, fetching weather data from an API, and saving/loading weather information to/from a MySQL database. The application features error handling for invalid city inputs and provides a user-friendly interface for displaying weather data.

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)
8 views23 pages

Yosup 21

The document outlines the implementation of a weather application named 'AeroMeter' using Python, MySQL, and Tkinter for the user interface. It includes functionalities for user sign-up and login, fetching weather data from an API, and saving/loading weather information to/from a MySQL database. The application features error handling for invalid city inputs and provides a user-friendly interface for displaying weather data.

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/ 23

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
# 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()
# 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()
# 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()
# 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()
# Weather App Functions

def data_get():
city = city_name.get()
data = requests.get(
f"https://api.openweathermap.org/data/2.5/weathe
r?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]["descriptio
n"])
temp_label1.config(text=str(int(data["main"]["temp"]
- 273.15)) + "°C")
per_label1.config(text=str(data["main"]["pressure"])
+ " hPa")
humidity_label1.config(text=str(data["main"]["humidi
ty"]) + " %")
wind_label1.config(text=str(data["wind"]["speed"]) +
" m/s")
visibility_label1.config(text=str(data["visibility"]
// 1000) + " km")
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")
# 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/weathe
r?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]["descriptio
n"])
temp_label1.config(text=str(int(data["main"]["temp"]
- 273.15)) + "°C")
per_label1.config(text=str(data["main"]["pressure"])
+ " hPa")
humidity_label1.config(text=str(data["main"]["humidi
ty"]) + " %")
wind_label1.config(text=str(data["wind"]["speed"]) +
" m/s")
visibility_label1.config(text=str(data["visibility"]
// 1000) + " km")
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["visibility
"])
except FileNotFoundError:
print("No saved data found.")
def refresh_data():
data_get()

win = Tk()
win.title("AeroMeter")
win.geometry("1408x704")
# Adding Background Image:
bg_image =
PhotoImage(file="D:\\pythonproject101\\projectpython23\\
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)
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)
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()
LOGIN PAGE
SIGN-UP PAGE
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
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
Entering state or
any city name
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.
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.
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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy