def searchCustomer(self): print("---- Customer Edit ----") print("1 . Find by customer's id.") print("2. Find by customer's phone number.") choice = input("Please enter your choice: ") if choice == "1": customer_id = input( "Please enter the id of the customer you would like to view: ") id_name = (customer_id, ) query = """select * from customers where id_number = %s""" cursor.execute(query, id_name) record = cursor.fetchall() if record == []: # In case the user entered an ID with letters if re.search('[a-zA-Z]', customer_id): print( "Customer's ID cannot contain a letter, exiting now.") exit(-1) # In case there is no customer with the entered ID print("Didn't find customer with id '{}', exiting now.".format( customer_id)) exit(-1) elif choice == "2": customer_phone = input( "Please enter the id of the customer you would like to edit: ") phone_num = (customer_phone, ) query = """select * from customers where phone = %s""" cursor.execute(query, phone_num) record = cursor.fetchall() if record == []: # In case the user entered an ID with letters if re.search('[a-zA-Z]', customer_phone): print( "Customer's phone number cannot contain a letter, exiting now." ) exit(-1) # In case there is no customer with the entered ID print("Didn't find customer with id '{}', exiting now.".format( customer_phone)) exit(-1) else: print("You have entered an incorrect number, please try again.") exit(-1) # Result display print("Result:") searchResult = BeautifulTable() searchResult.column_headers = [ "ID", "First Name", "Last Name", "City", "Address", "Email", "Phone", "User ID" ] # getting the values of each column set with ... if its too long searchResult.width_exceed_policy = BeautifulTable.WEP_ELLIPSIS # align center to each column searchResult.column_alignments = BeautifulTable.ALIGN_CENTER # style searchResult.set_style(BeautifulTable.STYLE_COMPACT) # Adding search results for row in record: searchResult.append_row(row) print(searchResult)
def createTable(header, rows): table = BeautifulTable() table.set_style(BeautifulTable.STYLE_BOX) if (len(header) > 0): table.column_headers = header for row in rows: table.append_row(row) table.column_alignments = BeautifulTable.ALIGN_LEFT print (table)
def getTable(data, columns=[]): table = BeautifulTable(max_width=1000) table.set_style(BeautifulTable.STYLE_COMPACT) table.column_headers = columns for row in data: table.append_row(row) table.column_alignments = BeautifulTable.ALIGN_LEFT return table
def displayConstumers(): customersTable = BeautifulTable() customersTable.column_headers = [ "ID", "First Name", "Last Name", "City", "Address", "Email", "Phone Number", "User ID" ] # getting the values of each column set with ... if its too long customersTable.width_exceed_policy = BeautifulTable.WEP_ELLIPSIS # align center to each column customersTable.column_alignments = BeautifulTable.ALIGN_CENTER # style customersTable.set_style(BeautifulTable.STYLE_COMPACT) # get rows of table from database query = "SELECT * FROM customers" cursor.execute(query) rows = cursor.fetchall() for row in rows: customersTable.append_row(row) print(customersTable)