Yash
Yash
connector
import datetime
cursor = airline_db.cursor()
Args:
None (user input requested within the function).
Returns:
None.
Examples:
Enter the Flight ID you want to update: 1
Enter the new flight name: Updated Flight
"""
# Prompt the user for the flight ID they want to update
flight_id = input("Enter the Flight ID you want to update: ")
if not existing_flight:
print("Flight with the provided ID does not exist.")
choice = int(input("Enter 1 if you want to enter new or otherwise: "))
if choice == 1:
add_flight()
else:
pass
return
if flight_name:
update_query += "flight_name = %s, "
update_values.append(flight_name)
if departure_city:
update_query += "departure_city = %s, "
update_values.append(departure_city)
if destination_city:
update_query += "destination_city = %s, "
update_values.append(destination_city)
if departure_date:
update_query += "departure_date = %s, "
update_values.append(departure_date)
if available_seats:
update_query += "available_seats = %s, "
update_values.append(available_seats)
try:
# Execute the UPDATE query with the new values
cursor.execute(update_query, update_values)
airline_db.commit()
print("Flight credentials updated successfully.")
except mysql.connector.Error as err:
print(f"Error: {err}")
This function allows an employee to add a new flight to the 'flights' table. It
prompts for flight details such as flight name, departure city, destination city,
departure date, and available seats.
Args:
None (user input requested within the function).
Returns:
None.
Examples:
Enter the flight name: New Flight
Enter the departure city: Departure City
"""
flight_name = input("Enter the flight name: ")
departure_city = input("Enter the departure city: ")
destination_city = input("Enter the destination city: ")
departure_date = input("Enter departure date (YYYY-MM-DD): ")
available_seats = int(input("Enter the number of available seats: "))
This function retrieves and displays a list of available flights from the
'flights' table. It provides information about each flight, including its ID, name,
departure city, destination city, departure date, and available seats.
Args:
None.
Returns:
None. (Prints the list of flights to the console)
Examples:
list_flights()
"""
cursor.execute("SELECT * FROM flights")
flights = cursor.fetchall()
if not flights:
print("No flights available.")
else:
print("Available Flights:")
for flight in flights:
print(f"Flight ID: {flight[0]}, Flight Name: {flight[1]}, Departure
City: {flight[2]}, Destination City: {flight[3]}, Departure Date: {flight[4]},
Available Seats: {flight[5]}")
if not flight:
# Flight does not exist
return False
Args:
None (user input requested within the function).
Returns:
None.
Examples:
Enter the flight ID you want to reserve a seat on: 1
Enter your username: Ankit
Enter the seat number you want to reserve: 5
"""
flight_id = input("Enter the flight ID you want to reserve a seat on: ")
This function fetches past flight reservations for a specific user and displays
them. It retrieves data from the 'past_reservations' and 'flights' tables, joining
them to provide a comprehensive list of past reservations.
Args:
username (str): The username for which past reservations are to be
retrieved.
Returns:
None. (Prints the past reservations to the console)
Examples:
view_past_reservations("Ankit")
"""
cursor.execute("""
SELECT pr.reservation_id, f.flight_name, f.departure_city,
f.destination_city, pr.seat_number, pr.reservation_date
FROM past_reservations pr
JOIN flights f ON pr.flight_id = f.flight_id
WHERE pr.username = %s
""", (username,))
past_reservations = cursor.fetchall()
if not past_reservations:
print("You have no past reservations.")
else:
print("Your Past Reservations:")
for reservation in past_reservations:
print(f"Reservation ID: {reservation[0]}, Flight Name:
{reservation[1]}, Departure City: {reservation[2]}, Destination City:
{reservation[3]}, Seat Number: {reservation[4]}, Reservation Date:
{reservation[5]}")
if user_row:
# Username exists in 'users' table
if user_row[3] == password: # Assuming the password column is at index 3
return True
else:
return "WRONG PASSWORD!"
else:
# User does not exist, so register the user
print("Oops! Looks like you are not registered in our database. :(")
choice = input("Enter 1 if you want to register or 2 to otherwise: ")
if choice == "1":
register_user(username, email, password)
else:
return True # Return True after registration
Args:
None (user input requested within the function).
Returns:
None.
Examples:
Enter the username of the user you want to update: Ankit
"""
username = input("Enter the username of the user you want to update: ")
if not existing_user:
print("User with the provided username does not exist.")
return
if choice == "1":
new_email = input("Enter the new email address: ")
cursor.execute("UPDATE users SET email = %s WHERE username = %s",
(new_email, username))
airline_db.commit()
print("User's email updated successfully.")
elif choice == "2":
new_password = input("Enter the new password: ")
cursor.execute("UPDATE users SET password = %s WHERE username = %s",
(new_password, username))
airline_db.commit()
print("User's password updated successfully.")
else:
print("Invalid choice.")
Args:
None (user input requested within the function).
Returns:
None.
Examples:
Enter the username of the user whose reservation you want to cancel or
update: john_doe
"""
username = input("Enter the username of the user whose reservation you want to
cancel or update: ")
if not existing_user:
print("User with the provided username does not exist.")
return
if not reservations:
print("No reservations found for this user.")
return
print("User's Reservations:")
for reservation in reservations:
print(f"Reservation ID: {reservation[0]}, Flight ID: {reservation[1]}, Seat
Number: {reservation[3]}")
print("Select the action you want to perform:")
print("1. Cancel Reservation")
print("2. Update Reservation")
if choice == "1":
reservation_id = input("Enter the Reservation ID you want to cancel: ")
cursor.execute("DELETE FROM reservations WHERE reservation_id = %s",
(reservation_id,))
airline_db.commit()
print("Reservation canceled successfully.")
elif choice == "2":
reservation_id = input("Enter the Reservation ID you want to update: ")
new_seat_number = input("Enter the new seat number: ")
cursor.execute("UPDATE reservations SET seat_number = %s WHERE
reservation_id = %s", (new_seat_number, reservation_id))
airline_db.commit()
print("Reservation updated successfully.")
else:
print("Invalid choice.")
Args:
None (user input requested within the function).
Returns:
None.
Examples:
Enter the Reservation ID you want to edit: 1
"""
reservation_id = input("Enter the Reservation ID you want to edit: ")
if not reservation_info:
print("Reservation with the provided ID does not exist.")
return
if choice == "1":
new_seat_number = input("Enter the new seat number: ")
if 1 <= int(new_seat_number) <= reservation_info[4]:
cursor.execute("UPDATE past_reservations SET seat_number = %s WHERE
reservation_id = %s", (new_seat_number, reservation_id))
airline_db.commit()
print("Reservation updated successfully.")
else:
print("Invalid seat number. Please select a valid seat.")
else:
print("Invalid choice.")
if choice == "1":
list_flights()
elif choice == "2":
reserve_seat()
elif choice == "3":
view_past_reservations(username)
elif choice == "4":
check = 1
else:
print("Invalid choice. Please try again.")
This function allows an employee to add a new user to the 'users' table. It
prompts for the new user's username, email, and password, performs a check to
ensure the username is unique, and adds the new user to the database.
Args:
None (user input requested within the function).
Returns:
None.
Examples:
Enter the username of the new user: new_user
"""
username = input("Enter the username of the new user: ")
email = input("Enter the email of the new user: ")
password = input("Enter the password for the new user: ")
This function allows an employee to remove an existing user from the 'users'
table. It prompts for the username of the user to be removed, verifies user
existence, and performs the user removal.
Args:
None (user input requested within the function).
Returns:
None.
Examples:
Enter the username of the user you want to remove: john_doe
"""
username = input("Enter the username of the user you want to remove: ")
if not existing_user:
print("User with the provided username does not exist.")
return
if choice == "1":
list_flights()
elif choice == "2":
update_flight_credentials()
elif choice == "3":
update_user_info()
elif choice == "4":
cancel_or_update_reservation()
elif choice == "5":
edit_past_reservations_by_employee()
elif choice == "6":
add_user_by_employee()
elif choice == "7":
remove_user_by_employee()
elif choice == "8":
check = 1
else:
print("Invalid choice. Please try again.")
if choice == "1":
user_menu()
elif choice == "2":
employee_menu()
elif choice == "3":
break
else:
print("Invalid choice. Please try again.")