Guest User

Untitled

a guest
Oct 6th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. import mysql.connector
  2.  
  3. import datetime
  4.  
  5. import constants
  6.  
  7. connection = mysql.connector.connect(user=constants.USERNAME,
  8. password=constants.PASSWORD,
  9. host=constants.HOST,
  10. database=constants.DB)
  11.  
  12. cursor = connection.cursor()
  13.  
  14. def vehicle_check(vehicle_no):
  15. global cursor
  16. cursor.execute("SELECT * FROM VEHICLES WHERE car_no='%s' " % (vehicle_no))
  17. result = len(cursor.fetchall())
  18. if(result==0):
  19. vehicle_add(vehicle_no)
  20.  
  21. def vehicle_add(vehicle_no):
  22. global cursor, connection
  23. company = input("Enter company name: ")
  24. model = input("Enter vehicle model: ")
  25. color = input("Enter vehicle color: ")
  26. cursor.execute("INSERT INTO vehicles VALUES('%s', '%s', '%s', '%s')" % (vehicle_no, company, model, color))
  27. connection.commit()
  28.  
  29. def employee_check(vehicle_no):
  30. global cursor
  31. cursor.execute("SELECT * FROM EMPLOYEES WHERE car_no='%s'" % (vehicle_no))
  32. result = len(cursor.fetchall())
  33. if(result==0):
  34. print("You are not registered as an employee.")
  35. non_employee_check(vehicle_no)
  36.  
  37. def non_employee_check(vehicle_no):
  38. global cursor
  39. cursor.execute("SELECT * FROM NONEMPLOYEES WHERE car_no='%s'" % (vehicle_no))
  40. result = len(cursor.fetchall())
  41. if(result==0):
  42. print("You are not registered in this parking lot yet.")
  43. non_employee_add(vehicle_no)
  44. else:
  45. pass # Print data
  46.  
  47. def non_employee_add(vehicle_no):
  48. global cursor, connection
  49. name = input("Enter your name: ")
  50. address = input("Enter your address: ")
  51. dob_inp = input("Enter your DOB(dd/mm/yyyy): ")
  52. dob = datetime.datetime.strptime(dob_inp, '%d/%m/%Y').date()
  53. cursor.execute("INSERT INTO NONEMPLOYEES (name,address, dob, car_no) VALUES('%s', '%s', '%s', '%s')" % (name, address, dob, vehicle_no))
  54. connection.commit()
  55.  
  56. def entry_vehicle(vehicle_no):
  57. global cursor, connection
  58. vehicle_check(vehicle_no)
  59. employee_check(vehicle_no)
  60. cursor.execute("SELECT spot from avail where available=true")
  61. spot = cursor.fetchall()
  62. if(spot!=None):
  63. spot = spot[0][0]
  64. print("You have been assigned spot %s" % spot)
  65. cursor.execute("UPDATE AVAIL SET AVAILABLE=false WHERE spot='%s'" % spot)
  66. connection.commit()
  67. t = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
  68. cursor.execute("INSERT INTO PARKERS (intime, car_no, spot) VALUES('%s', '%s', '%s')" % (t, vehicle_no, spot))
  69. connection.commit()
  70. else:
  71. print("No parking spot available")
  72.  
  73. def exit_vehicle(vehicle_no):
  74. global cursor, connection
  75. cursor.execute("SELECT * from PARKERS WHERE car_no='%s'" % vehicle_no)
  76. result = cursor.fetchall()
  77. if(len(result)!=0):
  78. result = result[0]
  79. t = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
  80. cursor.execute("UPDATE PARKERS SET OUTTIME='%s' WHERE log_no='%s'" % (t, result[0]))
  81. connection.commit()
  82. cursor.execute("UPDATE AVAIL SET AVAILABLE=true WHERE SPOT='%s'" % result[-1])
  83. connection.commit()
  84. print(result)
  85.  
  86. entry_vehicle('CG07LT2850')
  87. exit_vehicle('CG07LT2850')
Add Comment
Please, Sign In to add comment