From a173bc203a25a15decf098f50facdca9a80a0ae4 Mon Sep 17 00:00:00 2001 From: liuwei Date: Thu, 6 Feb 2025 16:39:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E9=97=BB=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base/func_xinghuo_web.py | 3 --- config.yaml | 4 ++-- message_report/write_db.py | 9 ++++++--- requirements.txt | 3 ++- robot.py | 6 +----- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/base/func_xinghuo_web.py b/base/func_xinghuo_web.py index f95f9ce..2023fd0 100644 --- a/base/func_xinghuo_web.py +++ b/base/func_xinghuo_web.py @@ -41,9 +41,6 @@ if __name__ == "__main__": "### 分类1" \ "1.#标题1" \ "2.#标题2" \ - "### 分类2" \ - "1.#标题3" \ - "2.#标题4" \ "分类之间使用--号进行分割,无内容则忽略该分组" \ "当前日期:2024年12月16日 星期一" \ "1. 标题: 安徽监狱回应李铁可否在监狱踢球" \ diff --git a/config.yaml b/config.yaml index 0fe339e..4b9cd05 100644 --- a/config.yaml +++ b/config.yaml @@ -39,10 +39,10 @@ logging: handlers: [console, info_file_handler, error_file_handler] groups: - enable: [45317011307@chatroom,49571962306@chatroom] # 允许响应的群 roomId,大概长这样:2xxxxxxxxx3@chatroom + enable: [45317011307@chatroom,49571962306@chatroom,43687793133@chatroom] # 允许响应的群 roomId,大概长这样:2xxxxxxxxx3@chatroom news: - receivers: [45317011307@chatroom,49571962306@chatroom] # 定时新闻接收人(roomid 或者 wxid) + receivers: [45317011307@chatroom,49571962306@chatroom,43687793133@chatroom] # 定时新闻接收人(roomid 或者 wxid) report_reminder: receivers: [] # 定时日报周报月报提醒(roomid 或者 wxid) diff --git a/message_report/write_db.py b/message_report/write_db.py index beb7a30..c6b4a85 100644 --- a/message_report/write_db.py +++ b/message_report/write_db.py @@ -27,7 +27,7 @@ def write_to_db(): # 遍历Redis中所有与昨天日期相关的key,并写入数据库 for key in r.keys(f"*:*:{yesterday}:count"): - # print('user key:' + key) + print('user key:' + key) parts = key.decode('utf-8').split(':') group_id, wx_id, _date = parts[0], parts[1], parts[2] # _date应该是yesterday,但这里为了完整性还是保留 count = int(r.hget(key, 'count')) if isinstance(r.hget(key, 'count'), bytes) else 0 # 处理可能的None或空值情况 @@ -48,11 +48,11 @@ def generate_and_send_ranking(groupId, allContacts: dict): yesterday = (datetime.now() - timedelta(days=1)).strftime('%Y-%m-%d') # 编写SQL查询来获取发言数量前20的用户 query = """ - SELECT group_id,wx_id, COUNT(*) AS speech_count + SELECT wx_id, count AS speech_count FROM speech_counts WHERE DATE(date) = DATE('now', '-1 day') AND group_id = ? - GROUP BY group_id,wx_id + GROUP BY wx_id ORDER BY count DESC LIMIT 20 """ @@ -71,3 +71,6 @@ def generate_and_send_ranking(groupId, allContacts: dict): # 这里我们没有实际“发送”排名,只是返回字符串 # 如果需要发送,可以在此添加发送逻辑 return ranking_str + +if __name__ == '__main__': + write_to_db() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index c9530f6..950c616 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,4 +20,5 @@ protobuf~=5.29.1 beautifulsoup4~=4.12.3 httpx~=0.28.1 pyttsx3~=2.98 -redis~=5.2.1 \ No newline at end of file +redis~=5.2.1 +PyMySQL~=1.1.1 \ No newline at end of file diff --git a/robot.py b/robot.py index d0fbbd1..45f23ac 100644 --- a/robot.py +++ b/robot.py @@ -306,11 +306,7 @@ class Robot(Job): "### 分类1" \ "1.#标题1" \ "2.#标题2" \ - "### 分类2" \ - "1.#标题3" \ - "2.#标题4" \ - "分类之间使用--号进行分割,无内容则忽略该分组" \ - + news) + "分类之间使用--号进行分割,无内容则忽略该分组" )+ news rsp = self.chat.get_answer(news) for r in receivers: