def main(): constants = Constants() database = Database() parse = Parse() grammar_config = Grammarconfig() user_command = "" query_suffix = '' if sys.argv[1][0:5] == constants.limit: query_suffix = ' ' + sys.argv[1] # First time search tips print(ct.Fore.MAGENTA + ct.Formatting.BOLD + constants.search_tips_001 + ct.Formatting.RESET_ALL) print(ct.Fore.MAGENTA + ct.Formatting.BOLD + constants.search_tips_002 + ct.Formatting.RESET_ALL) while user_command != constants.quit: print("") user_command = input(ct.Fore.MAGENTA + ct.Formatting.BOLD + constants.prompt + ct.Formatting.RESET_ALL) logging.info("User command: {}".format(user_command)) if user_command != constants.quit: query = parse.nl_command(user_command, grammar_config) if query != constants.failcode: if constants.limit not in query: # limit result set if set in runtime & not already restricted in query query = query + query_suffix try: database.execute_query(query) except mysql.connector.Error as err: logging.info("SQL query syntax error: {}".format(err)) else: database.output_results(database.cursor) else: print(ct.Fore.RED + ct.Formatting.BOLD + constants.dont_understand + ct.Formatting.RESET_ALL) logging.info("Query parsing failed") else: break database.cursor_close() database.connection_close() print(ct.Fore.MAGENTA + ct.Formatting.BOLD + constants.goodbye + ct.Formatting.RESET_ALL)