From 94654ac0c7374d61c9cbc79c67cfafcc7373c97b Mon Sep 17 00:00:00 2001 From: "Zhangzhichao@123" Date: Mon, 18 Aug 2025 10:03:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=90=AF=E5=8A=A8=E7=8A=B6?= =?UTF-8?q?=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helper.py | 5 +++-- liveMan.py | 10 ++++++++-- main.py | 4 +++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/helper.py b/helper.py index 761ed96..85aa55f 100644 --- a/helper.py +++ b/helper.py @@ -162,9 +162,10 @@ class LiveChatConfig: cursor.close() return int(livetalking_sessionid) - def update_chat_enable_status(self): + def update_chat_enable_status(self, status): + status_dict = {'未启动': 0, '启动中': 1, '已启动': 2, '启动失败': 3} cursor = self.conn.cursor() - cursor.execute("update live_config set value = 1 where key = 'chat_enable_status'") + cursor.execute("update live_config set value = ? where key = 'chat_enable_status'", (status_dict[status],)) self.conn.commit() cursor.close() diff --git a/liveMan.py b/liveMan.py index b14b688..307f328 100644 --- a/liveMan.py +++ b/liveMan.py @@ -96,6 +96,7 @@ class DouyinLiveWebFetcher: self.__ttwid = None self.__room_id = None self.live_id = LiveChatConfig().live_id + logger.info(f'self.live_id: {self.live_id}') self.live_url = "https://live.douyin.com/" self.user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " \ "Chrome/120.0.0.0 Safari/537.36" @@ -103,7 +104,12 @@ class DouyinLiveWebFetcher: self.ws_open_event = ws_open_event def start(self): - self._connectWebSocket() + try: + self._connectWebSocket() + except Exception as e: + live_chat_config.update_chat_enable_status('启动失败') + logger.error(traceback.format_exc()) + raise e def stop(self): self.ws.close() @@ -382,7 +388,7 @@ class DouyinLiveWebReply: """ 优先从用户交互队列中取提示词,如果没有用户交互的数据,则输出系统提示词 """ - live_chat_config.update_chat_enable_status() + live_chat_config.update_chat_enable_status('已启动') logger.info(f'livetalking address -> {self.live_chat_config.livetalking_address}') logger.info(f'ollama_address -> {self.live_chat_config.ollama_address}') while True: diff --git a/main.py b/main.py index c9e973f..79d1431 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,5 @@ from liveMan import DouyinLiveWebFetcher, DouyinLiveWebReply -from helper import PromptQueue +from helper import PromptQueue, LiveChatConfig from multiprocessing import Process, Event, freeze_support from loguru import logger @@ -19,6 +19,8 @@ def reply_user_chat_content(queue): if __name__ == '__main__': freeze_support() + LiveChatConfig().update_chat_enable_status('启动中') + queue = PromptQueue(10) ws_open_event = Event()