def check_input(data_driver): try: assert len(data_driver[0]) <= StandardValues.firstNameChars and data_driver[ 0] != "", "First Name must be less than or equal to " + str(StandardValues.firstNameChars) assert len(data_driver[1]) <= StandardValues.lastNameChars and data_driver[ 1] != "", "Last Name must be less than or equal to " + str(StandardValues.lastNameChars) assert len(data_driver[2]) <= StandardValues.addressChars and data_driver[ 2] != "", "Address must be less than or equal to " + str(StandardValues.addressChars) assert len(data_driver[3]) == 5 and data_driver[3] != "" and str( data_driver[3]).isdigit(), "Zip code should be 5 numbers" assert len(data_driver[5]) <= StandardValues.plateNumChars and data_driver[ 5] != "", "Plate number must be " + str(StandardValues.plateNumChars) + " characters." assert len(data_driver[6]) <= StandardValues.carmakeChars and data_driver[ 6] != "", "Car Make must be less than or equal to " + str(StandardValues.carmakeChars) assert len(data_driver[7]) <= StandardValues.modelChars and data_driver[ 7] != "", "Model must be less than or equal to " + str(StandardValues.modelChars) assert len(data_driver[8]) <= StandardValues.colorChars and data_driver[ 8] != "", "Color must be less than or equal to " + str(StandardValues.colorChars) except AssertionError as ae: Error.error_window(ae.__str__()) return -1 except ValueError as ve: Error.error_window(ve.__str__()) return -1 return 0
def check_openalpr(): try: assert read_a_plate('../img/mt.jpg', 'mt')[0] == 'BJR216' assert read_a_plate('../img/ca.jpeg', 'ca')[0] == '7VDV740' except AssertionError as ae: Error.error_window("OpenALPR failure") return -1 return 0
def check_file_input(img): try: check_opened_file = open(img, 'r') check_opened_file.close() except IOError: Error.error_window("File not found") return -1 return 0
def __init__(self, username, data_access): self.data_access = data_access try: name = self.find_user(username) if isinstance(name, AttributeError): raise AttributeError() self.passport = Passport(name[0][0], name[0][1], name[0][2], name[0][3]) except AttributeError as ae: Error.error_window("Could not retrieve account information") sys.exit(-1)
def connect(self): # uses the inputs from the user to log in try: # self.connection to AWS database new_conn = pymysql.connect(host='copproject.cveza4dgo3d2.us-east-2.rds.amazonaws.com', port=3306, user=StandardValues.username, passwd=StandardValues.password, db='poopproject') return new_conn except pymysql.OperationalError as oe: Error.error_window("Could not connect to database") print(oe) return pymysql.OperationalError
def add_driver(self, driver_data): cursor = self.conn.cursor() error = check_input(driver_data) if error == -1: return -1 # plate number duplication if self.plate_check(driver_data[5]) == 1: Error.error_window("Duplicate License Plate Number") return -1 cursor = self.conn.cursor() # runs query against database add_driver = ("INSERT INTO drivers " " (fname, lname, address, zipcod, state, platenum, carmake, color, model, priority) " " VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s); ") # execute query cursor.execute(add_driver, driver_data) self.conn.commit() cursor.close()
def find_user(self, login_name): try: self.data_access.cursor = self.data_access.conn.cursor() self.data_access.cursor.execute( "SELECT * FROM users WHERE (loginname = %s) ; ", login_name) rows = self.data_access.cursor.fetchall() if self.data_access.cursor.rowcount <= 0: self.data_access.cursor.close() raise PermissionError() self.data_access.cursor.close() return rows except AttributeError as ae: Error.error_window("No database connection") return ae except PermissionError as pe: Error.error_window("Invalid username") return pe except OSError as os: Error.error_window("Problem with access to database") return os
def __init__(self, username, password): self.conn = self.connect() self.user = dbUsers.Users(username, self) if not self.is_right_password(password): Error.error_window("Invalid password")