import os
import platform
import mysql.connector
def connect_db():
return mysql.connector.connect(host="localhost", user="root", password="root", database='parking')
def Add_Record(mycursor):
L = []
id1 = int(input("Enter the parking number : "))
L.append(id1)
pname1 = input("Enter the Parking Name: ")
L.append(pname1)
level1 = input("Enter level of parking : ")
L.append(level1)
freespace1 = input("Is there any freespace or not : YES/NO ")
L.append(freespace1)
vehicleno1 = input("Enter the Vehicle Number : ")
L.append(vehicleno1)
nod1 = int(input("Enter total number of days for parking: "))
L.append(nod1)
# Payment calculation
Payment1 = 20 * nod1 if nod1 <= 5 else 6969
L.append(Payment1)
stud = tuple(L)
sql = 'INSERT INTO parkmaster12(pid, pnm, level, freespace, vehicleno, nod, payment) VALUES(%s, %s, %s, %s, %s, %s, %s)'
mycursor.execute(sql, stud)
def Rec_View(mycursor):
print("Select the search criteria : ")
print("1. Parking Number")
print("2. Parking Name")
print("3. Level No")
print("4. All")
ch = int(input("Enter the choice : "))
if ch == 1:
s = int(input("Enter Parking no : "))
sql = "SELECT * FROM parkmaster12 WHERE pid=%s"
mycursor.execute(sql, (s,))
elif ch == 2:
s = input("Enter Parking Name : ")
sql = "SELECT * FROM parkmaster12 WHERE pnm=%s"
mycursor.execute(sql, (s,))
elif ch == 3:
s = input("Enter Level of Parking : ")
sql = "SELECT * FROM parkmaster12 WHERE level=%s"
mycursor.execute(sql, (s,))
elif ch == 4:
sql = "SELECT * FROM parkmaster12"
mycursor.execute(sql)
res = mycursor.fetchall()
print("Details about Parking are as follows : ")
print("(Parking Id, Parking Name, Level, FreeSpace(Y/N), Vehicle No, No of days for parking, Payment)")
for x in res:
print(x)
def Vehicle_Detail(mycursor):
L = []
vid1 = int(input("Enter Vehicle No : "))
L.append(vid1)
vnm1 = input("Enter Vehicle Name/Model Name : ")
L.append(vnm1)
dateofpur1 = input("Enter Year-Month-Date of purchase : ")
L.append(dateofpur1)
vdt = tuple(L)
sql = "INSERT INTO vehicle(vid, vnm, dateofpur) VALUES(%s, %s, %s)"
mycursor.execute(sql, vdt)
def Vehicle_View(mycursor):
vid1 = int(input("Enter the vehicle number of the vehicle whose details is to be viewed : "))
sql = 'SELECT parkmaster12.pid, parkmaster12.pnm, parkmaster12.vehicleno, vehicle.vid, vehicle.vnm FROM parkmaster12 INNER JOIN vehicle ON parkmaster12.pid=vehicle.vid WHERE vehicle.vid=%s'
mycursor.execute(sql, (vid1,))
res = mycursor.fetchall()
print('The following are the details you wanted:')
for x in res:
print(x)
def remove(mycursor):
vid1 = int(input("Enter the vehicle number of the vehicle to be deleted : "))
sql = "DELETE FROM vehicle WHERE vid=%s"
mycursor.execute(sql, (vid1,))
print('Removed as per the command')
def Menu(mycursor):
print("Enter 1 : To Add Parking Detail")
print("Enter 2 : To View Parking Detail ")
print("Enter 3 : To Add Vehicle Detail ")
print("Enter 4 : To Remove Vehicle Record")
print("Enter 5 : To see the details of Vehicle")
input_dt = int(input("Please Select An Above Option: "))
if input_dt == 1:
Add_Record(mycursor)
elif input_dt == 2:
Rec_View(mycursor)
elif input_dt == 3:
Vehicle_Detail(mycursor)
elif input_dt == 4:
remove(mycursor)
elif input_dt == 5:
Vehicle_View(mycursor)
else:
print("Enter correct choice....")
def run():
mydb = connect_db()
mycursor = mydb.cursor()
while True:
Menu(mycursor)
runAgn = input('\nWant to run Again Y/n: ')
if runAgn.lower() != 'y':
break
mydb.close()
run()