update code

This commit is contained in:
lychang
2025-11-13 23:59:28 +08:00
parent 764146278e
commit 00545db202
4 changed files with 72 additions and 18 deletions

View File

@@ -162,21 +162,22 @@ agent = AIAgent(max_retries=1, timeout=180)
class ChatSessionManager:
"""聊天会话管理器类"""
def __init__(self, chat_history_dir: str = "./"):
def __init__(self, online_db_uri: str = "zysl-log/wework/chat_msg/db/data.db"):
"""
初始化聊天会话管理器
Args:
chat_history_dir: 聊天历史文件目录
online_db_uri: 在线数据库URI
"""
self.chat_history_dir = chat_history_dir
self.files_dir = os.path.join(chat_history_dir, "files")
self.messages_dir = os.path.join(chat_history_dir, "messages")
self.db_path = os.path.join("db", "data.sqlite")
self.online_db_uri = online_db_uri
self.files_dir = os.path.join("", "files")
self.messages_dir = os.path.join("", "messages")
self.db_path = os.path.join("db", "data")
self.cache_path = None
# 初始化文件管理器
self.obj = ObjectFileManager()
self.lfm = LocalFileManager(self.files_dir)
self.dbm = LocalFileManager("db")
self.users = []
self.groups = []
self.members = {}
@@ -190,6 +191,23 @@ class ChatSessionManager:
os.makedirs(self.files_dir, exist_ok=True)
os.makedirs(self.messages_dir, exist_ok=True)
def upload_db(self):
file = self.dbm.get_file("data")
self.obj.upload_file(self.online_db_uri, file)
def download_db(self):
file = self.obj.get_file(self.online_db_uri)
l = self.dbm.upload_file("data", file)
def status(self):
cursor = self.conn.cursor()
cursor.execute("SELECT datetime FROM information order by datetime desc limit 1")
row = cursor.fetchone()
if row:
return row[0]
else:
return None
def download_chat_history(self, year: int, month: int, day: int, hour: int) -> bool:
"""
下载指定时间的聊天历史
@@ -621,9 +639,11 @@ class ChatSessionManager:
data = []
cursor = self.conn.cursor()
index_id = cursor.execute('''select id
from qa order by id desc limit 1''').fetchone()[0]
from qa
order by id desc
limit 1''').fetchone()[0]
for r in group_qa:
for r in group_qa:
qas = group_qa.get(r, {})
for qa in qas:
Q = qa["question"]
@@ -679,11 +699,12 @@ class ChatSessionManager:
if __name__ == '__main__':
chat_session = ChatSessionManager()
chat_session.upload_db()
chat_session.download_db()
# for day in range(11,13):
# for hour in range(24):
# chat_session.process_chat_session(2025,11,day,hour)
start = "2025-11-11 00:00:00"
# start = "2025-11-11 00:00:00"
# end = "2025-11-13 00:00:00"
end = "2025-11-12 23:59:59"
chat_session.update_qa_data(start, end)
#
# chat_session.update_qa_data(start, end)