diff --git a/func_box.py b/func_box.py index b146647..225c183 100644 --- a/func_box.py +++ b/func_box.py @@ -287,8 +287,8 @@ def diff_list(txt='', percent=0.70, switch: list = None, lst: list = None, sp=15 import difflib count_dict = {} if not lst: - lst = SqliteHandle('ai_common').get_prompt_value() - lst.update(SqliteHandle(f"ai_private_{hosts}").get_prompt_value()) + lst = SqliteHandle('ai_common').get_prompt_value(txt) + lst.update(SqliteHandle(f"ai_private_{hosts}").get_prompt_value(txt)) # diff 数据,根据precent系数归类数据 for i in lst: found = False @@ -378,10 +378,10 @@ def prompt_retrieval(is_all, hosts='', search=False): if '所有人' in is_all: for tab in SqliteHandle('ai_common').get_tables(): if tab.startswith('prompt'): - data = SqliteHandle(tab).get_prompt_value() + data = SqliteHandle(tab).get_prompt_value(None) if data: count_dict.update(data) elif '个人' in is_all: - data = SqliteHandle(f'prompt_{hosts}').get_prompt_value() + data = SqliteHandle(f'prompt_{hosts}').get_prompt_value(None) if data: count_dict.update(data) retrieval = [] if count_dict != {}: diff --git a/prompt_generator.py b/prompt_generator.py index b814160..0cf1415 100644 --- a/prompt_generator.py +++ b/prompt_generator.py @@ -41,7 +41,7 @@ class SqliteHandle: self.__connect.close() def create_tab(self): - self.__cursor.execute(f"CREATE TABLE `{self.__table}` ( 'prompt' TEXT, 'result' TEXT)") + self.__cursor.execute(f"CREATE TABLE `{self.__table}` ('prompt' TEXT UNIQUE, 'result' TEXT)") def get_tables(self): all_tab = [] @@ -50,16 +50,19 @@ class SqliteHandle: all_tab.append(tab[0]) return all_tab - def get_prompt_value(self): + def get_prompt_value(self, find): temp_all = {} - result = self.__cursor.execute(f"SELECT prompt, result FROM `{self.__table}`").fetchall() + if find: + result = self.__cursor.execute(f"SELECT prompt, result FROM `{self.__table}` WHERE prompt LIKE '%{find}%'").fetchall() + else: + result = self.__cursor.execute(f"SELECT prompt, result FROM `{self.__table}`").fetchall() for row in result: temp_all[row[0]] = row[1] return temp_all def inset_prompt(self, prompt: dict): for key in prompt: - self.__cursor.execute(f"INSERT INTO `{self.__table}` (prompt, result) VALUES (?, ?);", (str(key), str(prompt[key]))) + self.__cursor.execute(f"REPLACE INTO `{self.__table}` (prompt, result) VALUES (?, ?);", (str(key), str(prompt[key]))) self.__connect.commit() def delete_prompt(self):