From d818ba1be2f580bc55e060af59123b6d312ae0a3 Mon Sep 17 00:00:00 2001 From: w_xiaolizu Date: Tue, 6 Jun 2023 14:23:52 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=87=E6=BB=A4=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E4=B8=AD=E5=A4=9A=E4=BD=99=E7=9A=84=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- prompt_generator.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/prompt_generator.py b/prompt_generator.py index 0cf1415..9f0f9d1 100644 --- a/prompt_generator.py +++ b/prompt_generator.py @@ -24,8 +24,9 @@ def connect_db_close(cls_method): class SqliteHandle: - def __init__(self, table='ai_common'): - self.__connect = sqlite3.connect(os.path.join(prompt_path, 'ai_prompt.db')) + def __init__(self, table='ai_common', database='ai_prompt.db'): + self.__database = database + self.__connect = sqlite3.connect(os.path.join(prompt_path, self.__database)) self.__cursor = self.__connect.cursor() self.__table = table if self.__table not in self.get_tables(): @@ -33,7 +34,7 @@ class SqliteHandle: def new_connect_db(self): """多线程操作时,每个线程新建独立的connect""" - self.__connect = sqlite3.connect(os.path.join(prompt_path, 'ai_prompt.db')) + self.__connect = sqlite3.connect(os.path.join(prompt_path, self.__database)) self.__cursor = self.__connect.cursor() def new_close_db(self): @@ -50,7 +51,7 @@ class SqliteHandle: all_tab.append(tab[0]) return all_tab - def get_prompt_value(self, find): + def get_prompt_value(self, find=None): temp_all = {} if find: result = self.__cursor.execute(f"SELECT prompt, result FROM `{self.__table}` WHERE prompt LIKE '%{find}%'").fetchall() @@ -71,6 +72,8 @@ class SqliteHandle: sqlite_handle = SqliteHandle if __name__ == '__main__': - test = func_box.YamlHandle('/Users/kilig/Job/Python-project/academic_gpt/prompt_users/prompt_127.0.0.1.yaml').load() - - sqlite_handle('prompt_127.0.0.1').inset_prompt(test) \ No newline at end of file + sql_ll = sqlite_handle(database='ai_prompt_cp.db') + tabs = sql_ll.get_tables() + for i in tabs: + old_data = sqlite_handle(table=i, database='ai_prompt_cp.db').get_prompt_value() + sqlite_handle(table=i).inset_prompt(old_data)