fork download
  1. import mysql.connector
  2. from mysql.connector import Error
  3. import random
  4. from tabulate import tabulate
  5.  
  6.  
  7. conn = mysql.connector.connect(host = 'localhost', user = 'root', password ='root', database = 'flight_db',auth_plugin = 'mysql_native_password')
  8. cursor = conn.cursor()
  9.  
  10. # Create cus_details table
  11. cursor.execute('''
  12. CREATE TABLE IF NOT EXISTS cus_details (
  13. primary_key INT PRIMARY KEY,
  14. cus_name VARCHAR(100),
  15. fl_details INT,
  16. fl_name VARCHAR(100),
  17. dept VARCHAR(100),
  18. dest VARCHAR(100),
  19. f_time TIME,
  20. price INT
  21. );
  22. ''')
  23.  
  24. # Create food_item table
  25. cursor.execute('''
  26. CREATE TABLE IF NOT EXISTS food_item (
  27. sl_number INTEGER PRIMARY KEY,
  28. food_item_name TEXT,
  29. worker TEXT
  30. );
  31. ''')
  32.  
  33. # Create luggage table
  34. cursor.execute('''
  35. CREATE TABLE IF NOT EXISTS luggage (
  36. luggage_id INTEGER PRIMARY KEY,
  37. luggage_type TEXT,
  38. owner_name TEXT
  39. );
  40. ''')
  41.  
  42. # Create flight_details table
  43. cursor.execute('''
  44. CREATE TABLE IF NOT EXISTS flight_details (
  45. flight_id INTEGER PRIMARY KEY,
  46. flight_name TEXT,
  47. flight_price TEXT,
  48. departure TEXT,
  49. destination TEXT,
  50. day TEXT,
  51. time TEXT,
  52. business INTEGER
  53. );
  54. ''')
  55.  
  56. # Commit changes and close the connection
  57. conn.commit()
  58.  
  59. # Close the connection
  60. conn.close()
  61.  
  62. print("Tables created successfully!")
  63.  
  64.  
  65. # Insert default values into cus_details
  66. cursor.executemany('''
  67. INSERT OR REPLACE INTO cus_details (primary_key, cus_name, fl_details, fl_name, dept, dest, f_time, price)
  68. VALUES (?, ?, ?, ?, ?, ?, ?, ?)
  69. ''', [
  70. (1, 'John Doe', 101, 'Air India AI202', 'Delhi', 'Mumbai', '10:30:00', 5000),
  71. (2, 'Jane Smith', 102, 'IndiGo 6E303', 'Mumbai', 'Chennai', '12:45:00', 4500),
  72. (3, 'Sam Wilson', 103, 'SpiceJet SG101', 'Bangalore', 'Kolkata', '06:00:00', 4000),
  73. (4, 'Anna Brown', 104, 'Vistara UK102', 'Hyderabad', 'Delhi', '08:15:00', 5500)
  74. ])
  75.  
  76. # Insert default values into food_item
  77. cursor.executemany('''
  78. INSERT OR REPLACE INTO food_item (sl_number, food_item_name, worker)
  79. VALUES (?, ?, ?)
  80. ''', [
  81. (1, 'Pizza', 'John'),
  82. (2, 'Burger', 'Emma'),
  83. (3, 'Pasta', 'Liam'),
  84. (4, 'Salad', 'Sophia')
  85. ])
  86.  
  87.  
  88. # Insert default values into luggage
  89. cursor.executemany('''
  90. INSERT OR REPLACE INTO luggage (luggage_id, luggage_type, owner_name)
  91. VALUES (?, ?, ?)
  92. ''', [
  93. (101, 'Suitcase', 'Michael'),
  94. (102, 'Backpack', 'Olivia'),
  95. (103, 'Duffel Bag', 'Noah'),
  96. (104, 'Trolley Bag', 'Isabella')
  97. ])
  98.  
  99. # Insert default values into flight_details
  100. cursor.executemany('''
  101. INSERT OR REPLACE INTO flight_details (flight_id, flight_name, departure, destination, day, time, business)
  102. VALUES (?, ?, ?, ?, ?, ?, ?)
  103. ''', [
  104. (1, 'Air India AI202', 'Delhi', 'Mumbai', 'Monday', '10:30 AM', 50),
  105. (2, 'IndiGo 6E303', 'Mumbai', 'Chennai', 'Tuesday', '2:45 PM', 30),
  106. (3, 'SpiceJet SG101', 'Bangalore', 'Kolkata', 'Wednesday', '6:00 AM', 40),
  107. (4, 'Vistara UK102', 'Hyderabad', 'Delhi', 'Friday', '8:15 PM', 60)
  108. ])
  109.  
  110. # Commit changes and close the connection
  111. conn.commit()
  112.  
  113. # Close the connection
  114. conn.close()
  115.  
  116. print("Tables and default values inserted successfully!")
  117.  
  118.  
  119.  
  120. import sqlite3
  121.  
  122. # Connect to SQLite database
  123. conn = sqlite3.connect('items.db')
  124. cursor = conn.cursor()
  125.  
  126. # Client functions
  127. def fetch_flight_details():
  128. print("THE AVAILABLE FLIGHTS ARE: ")
  129. print(" ")
  130. cursor.execute("SELECT * FROM flight_details")
  131. flights = cursor.fetchall()
  132. print("\nFlight Details:")
  133. for flight in flights:
  134. print(f"ID: {flight[0]}, Name: {flight[1]}, Departure: {flight[2]}, Destination: {flight[3]}, Day: {flight[4]}, Time: {flight[5]}, Business Seats: {flight[6]}")
  135.  
  136. def fetch_food_details():
  137. print(" THE AVAILABLE FOODS ARE: ")
  138. print(" ")
  139. cursor.execute("SELECT * FROM food_item")
  140. foods = cursor.fetchall()
  141. print("\nFood Details:")
  142. for food in foods:
  143. print(f"Serial No: {food[0]}, Food Item: {food[1]}, Worker: {food[2]}")
  144.  
  145. def book_ticket():
  146. print("\nEnter details to book a ticket:")
  147. primary_key = int(input("Primary Key: "))
  148. cus_name = input("Customer Name: ")
  149. fl_details = int(input("Flight ID: "))
  150. fl_name = input("Flight Name: ")
  151. dept = input("Departure Location: ")
  152. dest = input("Destination: ")
  153. f_time = input("Flight Time (HH:MM:SS): ")
  154.  
  155.  
  156. cursor.execute("INSERT INTO cus_details (primary_key, cus_name, fl_details, fl_name, dept, dest, f_time) VALUES ({},'{}',{},'{}','{}','{}','{}',{})".format(primary_key, cus_name, fl_details, fl_name, dept, dest, f_time))
  157. conn.commit()
  158. print("Ticket booked successfully!")
  159.  
  160. def show_user_details():
  161. cursor.execute("SELECT * FROM cus_details")
  162. users = cursor.fetchall()
  163. print("\nUser Details:")
  164. for user in users:
  165. print(f"Primary Key: {user[0]}, Name: {user[1]}, Flight ID: {user[2]}, Flight Name: {user[3]}, Departure: {user[4]}, Destination: {user[5]}, Time: {user[6]}, Price: {user[7]}")
  166.  
  167. # Admin functions
  168. def change_flight_price():
  169. flight_id = int(input("Enter Flight ID to update price: "))
  170. new_price = int(input("Enter new price: "))
  171. cursor.execute("UPDATE flight_details SET business = ? WHERE flight_id = ?", (new_price, flight_id))
  172. conn.commit()
  173. print("Price updated successfully!")
  174.  
  175. def manage_food():
  176. print("\n1. Add Food Item")
  177. print("2. Remove Food Item")
  178. action = int(input("Choose action: "))
  179.  
  180. if action == 1:
  181. food_name = input("Enter food name: ")
  182. worker = input("Enter worker name: ")
  183. cursor.execute("INSERT INTO food_item (food_item_name, worker) VALUES (?, ?)", (food_name, worker))
  184. conn.commit()
  185. print(f"Food item '{food_name}' added.")
  186.  
  187. elif action == 2:
  188. food_id = int(input("Enter food serial number to remove: "))
  189. cursor.execute("DELETE FROM food_item WHERE sl_number = ?", (food_id,))
  190. conn.commit()
  191. print(f"Food item {food_id} removed.")
  192.  
  193. else:
  194. print("Invalid action.")
  195.  
  196. def manage_luggage():
  197. print("\n1. Add Luggage")
  198. print("2. Remove Luggage")
  199. action = int(input("Choose action: "))
  200.  
  201. if action == 1:
  202. luggage_type = input("Enter luggage type: ")
  203. owner_name = input("Enter owner's name: ")
  204. cursor.execute("INSERT INTO luggage (luggage_type, owner_name) VALUES (?, ?)", (luggage_type, owner_name))
  205. conn.commit()
  206. print(f"Luggage '{luggage_type}' added.")
  207.  
  208. elif action == 2:
  209. luggage_id = int(input("Enter luggage ID to remove: "))
  210. cursor.execute("DELETE FROM luggage WHERE luggage_id = ?", (luggage_id,))
  211. conn.commit()
  212. print(f"Luggage {luggage_id} removed.")
  213.  
  214. else:
  215. print("Invalid action.")
  216.  
  217.  
  218.  
  219.  
  220.  
  221. # Admin login
  222. def admin_login():
  223. password = input("Enter admin password: ")
  224. if password == "humanmade@123":
  225. print("Admin authenticated.")
  226. return True
  227. else:
  228. print("Incorrect password.")
  229. return False
  230.  
  231. # Main menu
  232. def main():
  233. print("****************** WELCOME TO LAMNIO AIRLINES**********************")
  234. print("************ MAKE YOUR JOURNEY SUCCESS WITH US!*****************")
  235. user_type = input("Are you an admin or client? (admin/client): ").strip().lower()
  236.  
  237. if user_type == 'admin':
  238. if admin_login():
  239. while True:
  240. print("\nAdmin Menu:")
  241. print("1. Change Flight Price")
  242. print("2. Manage Food Items")
  243. print("3. Manage Luggage")
  244. print("4. Exit")
  245. choice = int(input("Enter choice: "))
  246. if choice == 1:
  247. change_flight_price()
  248. elif choice == 2:
  249. manage_food()
  250. elif choice == 3:
  251. manage_luggage()
  252. elif choice == 4:
  253. print("Exiting admin panel.")
  254. break
  255. else:
  256. print("Invalid choice!")
  257.  
  258. elif user_type == 'client':
  259. while True:
  260. print("\nClient Menu:")
  261. print("1. Fetch Flight Details")
  262. print("2. Fetch Food Details")
  263. print("3. Book Ticket")
  264. print("4. Show User Details")
  265. print("5. Exit")
  266. choice = int(input("Enter choice: "))
  267.  
  268. if choice == 1:
  269. fetch_flight_details()
  270. elif choice == 2:
  271. fetch_food_details()
  272. elif choice == 3:
  273. book_ticket()
  274. elif choice == 4:
  275. show_user_details()
  276. elif choice == 5:
  277. print("Exiting program.")
  278. break
  279. else:
  280. print("Invalid choice!")
  281.  
  282. else:
  283. print("Invalid user type!")
  284.  
  285. main()
Success #stdin #stdout 0.04s 25900KB
stdin
Standard input is empty
stdout
import mysql.connector
from mysql.connector import Error
import random
from tabulate import tabulate


conn = mysql.connector.connect(host = 'localhost', user = 'root', password ='root', database = 'flight_db',auth_plugin = 'mysql_native_password')
cursor = conn.cursor()

# Create cus_details table
cursor.execute('''
    CREATE TABLE IF NOT EXISTS cus_details (
        primary_key INT PRIMARY KEY,
        cus_name VARCHAR(100),
        fl_details INT,
        fl_name VARCHAR(100),
        dept VARCHAR(100),
        dest VARCHAR(100),
        f_time TIME,
        price INT
    );
''')

# Create food_item table
cursor.execute('''
    CREATE TABLE IF NOT EXISTS food_item (
        sl_number INTEGER PRIMARY KEY,
        food_item_name TEXT,
        worker TEXT
    );
''')

# Create luggage table
cursor.execute('''
    CREATE TABLE IF NOT EXISTS luggage (
        luggage_id INTEGER PRIMARY KEY,
        luggage_type TEXT,
        owner_name TEXT
    );
''')

# Create flight_details table
cursor.execute('''
    CREATE TABLE IF NOT EXISTS flight_details (
        flight_id INTEGER PRIMARY KEY,
        flight_name TEXT,
        flight_price TEXT,
        departure TEXT,
        destination TEXT,
        day TEXT,
        time TEXT,
        business INTEGER
    );
''')

# Commit changes and close the connection
conn.commit()

# Close the connection
conn.close()

print("Tables created successfully!")


# Insert default values into cus_details
cursor.executemany('''
    INSERT OR REPLACE INTO cus_details (primary_key, cus_name, fl_details, fl_name, dept, dest, f_time, price)
    VALUES (?, ?, ?, ?, ?, ?, ?, ?)
''', [
    (1, 'John Doe', 101, 'Air India AI202', 'Delhi', 'Mumbai', '10:30:00', 5000),
    (2, 'Jane Smith', 102, 'IndiGo 6E303', 'Mumbai', 'Chennai', '12:45:00', 4500),
    (3, 'Sam Wilson', 103, 'SpiceJet SG101', 'Bangalore', 'Kolkata', '06:00:00', 4000),
    (4, 'Anna Brown', 104, 'Vistara UK102', 'Hyderabad', 'Delhi', '08:15:00', 5500)
])

# Insert default values into food_item
cursor.executemany('''
    INSERT OR REPLACE INTO food_item (sl_number, food_item_name, worker)
    VALUES (?, ?, ?)
''', [
    (1, 'Pizza', 'John'),
    (2, 'Burger', 'Emma'),
    (3, 'Pasta', 'Liam'),
    (4, 'Salad', 'Sophia')
])


# Insert default values into luggage
cursor.executemany('''
    INSERT OR REPLACE INTO luggage (luggage_id, luggage_type, owner_name)
    VALUES (?, ?, ?)
''', [
    (101, 'Suitcase', 'Michael'),
    (102, 'Backpack', 'Olivia'),
    (103, 'Duffel Bag', 'Noah'),
    (104, 'Trolley Bag', 'Isabella')
])

# Insert default values into flight_details
cursor.executemany('''
    INSERT OR REPLACE INTO flight_details (flight_id, flight_name, departure, destination, day, time, business)
    VALUES (?, ?, ?, ?, ?, ?, ?)
''', [
    (1, 'Air India AI202', 'Delhi', 'Mumbai', 'Monday', '10:30 AM', 50),
    (2, 'IndiGo 6E303', 'Mumbai', 'Chennai', 'Tuesday', '2:45 PM', 30),
    (3, 'SpiceJet SG101', 'Bangalore', 'Kolkata', 'Wednesday', '6:00 AM', 40),
    (4, 'Vistara UK102', 'Hyderabad', 'Delhi', 'Friday', '8:15 PM', 60)
])

# Commit changes and close the connection
conn.commit()

# Close the connection
conn.close()

print("Tables and default values inserted successfully!")



import sqlite3

# Connect to SQLite database
conn = sqlite3.connect('items.db')
cursor = conn.cursor()

# Client functions
def fetch_flight_details():
    print("THE AVAILABLE FLIGHTS ARE: ")
    print(" ")
    cursor.execute("SELECT * FROM flight_details")
    flights = cursor.fetchall()
    print("\nFlight Details:")
    for flight in flights:
        print(f"ID: {flight[0]}, Name: {flight[1]}, Departure: {flight[2]}, Destination: {flight[3]}, Day: {flight[4]}, Time: {flight[5]}, Business Seats: {flight[6]}")

def fetch_food_details():
    print(" THE AVAILABLE FOODS ARE: ")
    print(" ")
    cursor.execute("SELECT * FROM food_item")
    foods = cursor.fetchall()
    print("\nFood Details:")
    for food in foods:
        print(f"Serial No: {food[0]}, Food Item: {food[1]}, Worker: {food[2]}")

def book_ticket():
    print("\nEnter details to book a ticket:")
    primary_key = int(input("Primary Key: "))
    cus_name = input("Customer Name: ")
    fl_details = int(input("Flight ID: "))
    fl_name = input("Flight Name: ")
    dept = input("Departure Location: ")
    dest = input("Destination: ")
    f_time = input("Flight Time (HH:MM:SS): ")
    
    
    cursor.execute("INSERT INTO cus_details (primary_key, cus_name, fl_details, fl_name, dept, dest, f_time) VALUES ({},'{}',{},'{}','{}','{}','{}',{})".format(primary_key, cus_name, fl_details, fl_name, dept, dest, f_time))
    conn.commit()
    print("Ticket booked successfully!")

def show_user_details():
    cursor.execute("SELECT * FROM cus_details")
    users = cursor.fetchall()
    print("\nUser Details:")
    for user in users:
        print(f"Primary Key: {user[0]}, Name: {user[1]}, Flight ID: {user[2]}, Flight Name: {user[3]}, Departure: {user[4]}, Destination: {user[5]}, Time: {user[6]}, Price: {user[7]}")

# Admin functions
def change_flight_price():
    flight_id = int(input("Enter Flight ID to update price: "))
    new_price = int(input("Enter new price: "))
    cursor.execute("UPDATE flight_details SET business = ? WHERE flight_id = ?", (new_price, flight_id))
    conn.commit()
    print("Price updated successfully!")

def manage_food():
    print("\n1. Add Food Item")
    print("2. Remove Food Item")
    action = int(input("Choose action: "))
    
    if action == 1:
        food_name = input("Enter food name: ")
        worker = input("Enter worker name: ")
        cursor.execute("INSERT INTO food_item (food_item_name, worker) VALUES (?, ?)", (food_name, worker))
        conn.commit()
        print(f"Food item '{food_name}' added.")
        
    elif action == 2:
        food_id = int(input("Enter food serial number to remove: "))
        cursor.execute("DELETE FROM food_item WHERE sl_number = ?", (food_id,))
        conn.commit()
        print(f"Food item {food_id} removed.")
    
    else:
        print("Invalid action.")

def manage_luggage():
    print("\n1. Add Luggage")
    print("2. Remove Luggage")
    action = int(input("Choose action: "))
    
    if action == 1:
        luggage_type = input("Enter luggage type: ")
        owner_name = input("Enter owner's name: ")
        cursor.execute("INSERT INTO luggage (luggage_type, owner_name) VALUES (?, ?)", (luggage_type, owner_name))
        conn.commit()
        print(f"Luggage '{luggage_type}' added.")
        
    elif action == 2:
        luggage_id = int(input("Enter luggage ID to remove: "))
        cursor.execute("DELETE FROM luggage WHERE luggage_id = ?", (luggage_id,))
        conn.commit()
        print(f"Luggage {luggage_id} removed.")
    
    else:
        print("Invalid action.")





# Admin login
def admin_login():
    password = input("Enter admin password: ")
    if password == "humanmade@123":
        print("Admin authenticated.")
        return True
    else:
        print("Incorrect password.")
        return False

# Main menu
def main():
    print("****************** WELCOME TO LAMNIO AIRLINES**********************")
    print("************ MAKE YOUR JOURNEY SUCCESS WITH US!*****************")
    user_type = input("Are you an admin or client? (admin/client): ").strip().lower()
    
    if user_type == 'admin':
        if admin_login():
            while True:
                print("\nAdmin Menu:")
                print("1. Change Flight Price")
                print("2. Manage Food Items")
                print("3. Manage Luggage")
                print("4. Exit")
                choice = int(input("Enter choice: "))
                if choice == 1:
                    change_flight_price()
                elif choice == 2:
                    manage_food()
                elif choice == 3:
                    manage_luggage()
                elif choice == 4:
                    print("Exiting admin panel.")
                    break
                else:
                    print("Invalid choice!")
                    
    elif user_type == 'client':
        while True:
            print("\nClient Menu:")
            print("1. Fetch Flight Details")
            print("2. Fetch Food Details")
            print("3. Book Ticket")
            print("4. Show User Details")
            print("5. Exit")
            choice = int(input("Enter choice: "))
            
            if choice == 1:
                fetch_flight_details()
            elif choice == 2:
                fetch_food_details()
            elif choice == 3:
                book_ticket()
            elif choice == 4:
                show_user_details()
            elif choice == 5:
                print("Exiting program.")
                break
            else:
                print("Invalid choice!")
                
    else:
        print("Invalid user type!")

main()